blob: 7a216d478a943148bc0acf2845f0e4af2bf43fec [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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
37#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046#include "lpfc_version.h"
47
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050048static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050049static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
50static int lpfc_post_rcv_buf(struct lpfc_hba *);
51
52static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050053static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050054static DEFINE_IDR(lpfc_hba_index);
55
James Smarte59058c2008-08-24 21:49:00 -040056/**
57 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
58 * @phba: pointer to lpfc hba data structure.
59 *
60 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
61 * mailbox command. It retrieves the revision information from the HBA and
62 * collects the Vital Product Data (VPD) about the HBA for preparing the
63 * configuration of the HBA.
64 *
65 * Return codes:
66 * 0 - success.
67 * -ERESTART - requests the SLI layer to reset the HBA and try again.
68 * Any other value - indicates an error.
69 **/
dea31012005-04-17 16:05:31 -050070int
James Smart2e0fef82007-06-17 19:56:36 -050071lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050072{
73 lpfc_vpd_t *vp = &phba->vpd;
74 int i = 0, rc;
75 LPFC_MBOXQ_t *pmb;
76 MAILBOX_t *mb;
77 char *lpfc_vpd_data = NULL;
78 uint16_t offset = 0;
79 static char licensed[56] =
80 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040081 static int init_key = 1;
dea31012005-04-17 16:05:31 -050082
83 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
84 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050085 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050086 return -ENOMEM;
87 }
88
89 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050090 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050091
92 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040093 if (init_key) {
94 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050095
James Smart65a29c12006-07-06 15:50:50 -040096 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
97 *ptext = cpu_to_be32(*ptext);
98 init_key = 0;
99 }
dea31012005-04-17 16:05:31 -0500100
101 lpfc_read_nv(phba, pmb);
102 memset((char*)mb->un.varRDnvp.rsvd3, 0,
103 sizeof (mb->un.varRDnvp.rsvd3));
104 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
105 sizeof (licensed));
106
107 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
108
109 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500110 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400111 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500112 "error, mbxCmd x%x READ_NVPARM, "
113 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500114 mb->mbxCommand, mb->mbxStatus);
115 mempool_free(pmb, phba->mbox_mem_pool);
116 return -ERESTART;
117 }
118 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500119 sizeof(phba->wwnn));
120 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
121 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500122 }
123
James Smart92d7f7b2007-06-17 19:56:38 -0500124 phba->sli3_options = 0x0;
125
dea31012005-04-17 16:05:31 -0500126 /* Setup and issue mailbox READ REV command */
127 lpfc_read_rev(phba, pmb);
128 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
129 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400131 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500132 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500133 mb->mbxCommand, mb->mbxStatus);
134 mempool_free( pmb, phba->mbox_mem_pool);
135 return -ERESTART;
136 }
137
James Smart92d7f7b2007-06-17 19:56:38 -0500138
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500139 /*
140 * The value of rr must be 1 since the driver set the cv field to 1.
141 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500142 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500143 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500144 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400146 "0440 Adapter failed to init, READ_REV has "
147 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500148 mempool_free(pmb, phba->mbox_mem_pool);
149 return -ERESTART;
dea31012005-04-17 16:05:31 -0500150 }
151
James Smart495a7142008-06-14 22:52:59 -0400152 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
153 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500154 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400155 }
James Smarted957682007-06-17 19:56:37 -0500156
dea31012005-04-17 16:05:31 -0500157 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500158 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500159 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500160 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
161 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
162 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
163 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500164 vp->rev.biuRev = mb->un.varRdRev.biuRev;
165 vp->rev.smRev = mb->un.varRdRev.smRev;
166 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
167 vp->rev.endecRev = mb->un.varRdRev.endecRev;
168 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
169 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
170 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
171 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
172 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
173 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
174
James Smart92d7f7b2007-06-17 19:56:38 -0500175 /* If the sli feature level is less then 9, we must
176 * tear down all RPIs and VPIs on link down if NPIV
177 * is enabled.
178 */
179 if (vp->rev.feaLevelHigh < 9)
180 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
181
dea31012005-04-17 16:05:31 -0500182 if (lpfc_is_LC_HBA(phba->pcidev->device))
183 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
184 sizeof (phba->RandomData));
185
dea31012005-04-17 16:05:31 -0500186 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500187 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
188 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400189 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500190
191 do {
192 lpfc_dump_mem(phba, pmb, offset);
193 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
194
195 if (rc != MBX_SUCCESS) {
196 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400197 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500198 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500199 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500200 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500201 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500202 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
203 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400204 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
205 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500206 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500207 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500208 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
209 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500210
211 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500212out_free_mbox:
213 mempool_free(pmb, phba->mbox_mem_pool);
214 return 0;
215}
216
James Smarte59058c2008-08-24 21:49:00 -0400217/**
218 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
219 * @phba: pointer to lpfc hba data structure.
220 * @pmboxq: pointer to the driver internal queue element for mailbox command.
221 *
222 * This is the completion handler for driver's configuring asynchronous event
223 * mailbox command to the device. If the mailbox command returns successfully,
224 * it will set internal async event support flag to 1; otherwise, it will
225 * set internal async event support flag to 0.
226 **/
James Smart57127f12007-10-27 13:37:05 -0400227static void
228lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
229{
230 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
231 phba->temp_sensor_support = 1;
232 else
233 phba->temp_sensor_support = 0;
234 mempool_free(pmboxq, phba->mbox_mem_pool);
235 return;
236}
237
James Smarte59058c2008-08-24 21:49:00 -0400238/**
James Smart97207482008-12-04 22:39:19 -0500239 * lpfc_dump_wakeup_param_cmpl: Completion handler for dump memory mailbox
240 * command used for getting wake up parameters.
241 * @phba: pointer to lpfc hba data structure.
242 * @pmboxq: pointer to the driver internal queue element for mailbox command.
243 *
244 * This is the completion handler for dump mailbox command for getting
245 * wake up parameters. When this command complete, the response contain
246 * Option rom version of the HBA. This function translate the version number
247 * into a human readable string and store it in OptionROMVersion.
248 **/
249static void
250lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
251{
252 struct prog_id *prg;
253 uint32_t prog_id_word;
254 char dist = ' ';
255 /* character array used for decoding dist type. */
256 char dist_char[] = "nabx";
257
James Smart9f1e1b52008-12-04 22:39:40 -0500258 if (pmboxq->mb.mbxStatus != MBX_SUCCESS) {
259 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500260 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500261 }
James Smart97207482008-12-04 22:39:19 -0500262
263 prg = (struct prog_id *) &prog_id_word;
264
265 /* word 7 contain option rom version */
266 prog_id_word = pmboxq->mb.un.varWords[7];
267
268 /* Decode the Option rom version word to a readable string */
269 if (prg->dist < 4)
270 dist = dist_char[prg->dist];
271
272 if ((prg->dist == 3) && (prg->num == 0))
273 sprintf(phba->OptionROMVersion, "%d.%d%d",
274 prg->ver, prg->rev, prg->lev);
275 else
276 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
277 prg->ver, prg->rev, prg->lev,
278 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500279 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500280 return;
281}
282
283/**
James Smarte59058c2008-08-24 21:49:00 -0400284 * lpfc_config_port_post: Perform lpfc initialization after config port.
285 * @phba: pointer to lpfc hba data structure.
286 *
287 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
288 * command call. It performs all internal resource and state setups on the
289 * port: post IOCB buffers, enable appropriate host interrupt attentions,
290 * ELS ring timers, etc.
291 *
292 * Return codes
293 * 0 - success.
294 * Any other value - error.
295 **/
dea31012005-04-17 16:05:31 -0500296int
James Smart2e0fef82007-06-17 19:56:36 -0500297lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500298{
James Smart2e0fef82007-06-17 19:56:36 -0500299 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500300 LPFC_MBOXQ_t *pmb;
301 MAILBOX_t *mb;
302 struct lpfc_dmabuf *mp;
303 struct lpfc_sli *psli = &phba->sli;
304 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500305 int i, j;
306 int rc;
dea31012005-04-17 16:05:31 -0500307
James Smart7af67052007-10-27 13:38:11 -0400308 spin_lock_irq(&phba->hbalock);
309 /*
310 * If the Config port completed correctly the HBA is not
311 * over heated any more.
312 */
313 if (phba->over_temp_state == HBA_OVER_TEMP)
314 phba->over_temp_state = HBA_NORMAL_TEMP;
315 spin_unlock_irq(&phba->hbalock);
316
dea31012005-04-17 16:05:31 -0500317 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
318 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500319 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500320 return -ENOMEM;
321 }
322 mb = &pmb->mb;
323
dea31012005-04-17 16:05:31 -0500324 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500325 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500326 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500327 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400329 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500330 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500331 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500332 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500333 mp = (struct lpfc_dmabuf *) pmb->context1;
334 mempool_free( pmb, phba->mbox_mem_pool);
335 lpfc_mbuf_free(phba, mp->virt, mp->phys);
336 kfree(mp);
337 return -EIO;
338 }
339
340 mp = (struct lpfc_dmabuf *) pmb->context1;
341
James Smart2e0fef82007-06-17 19:56:36 -0500342 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500343 lpfc_mbuf_free(phba, mp->virt, mp->phys);
344 kfree(mp);
345 pmb->context1 = NULL;
346
James Smarta12e07b2006-12-02 13:35:30 -0500347 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500348 u64_to_wwn(phba->cfg_soft_wwnn,
349 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400350 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500351 u64_to_wwn(phba->cfg_soft_wwpn,
352 vport->fc_sparam.portName.u.wwn);
353 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500354 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500355 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500356 sizeof (struct lpfc_name));
357 /* If no serial number in VPD data, use low 6 bytes of WWNN */
358 /* This should be consolidated into parse_vpd ? - mr */
359 if (phba->SerialNumber[0] == 0) {
360 uint8_t *outptr;
361
James Smart2e0fef82007-06-17 19:56:36 -0500362 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500363 for (i = 0; i < 12; i++) {
364 status = *outptr++;
365 j = ((status & 0xf0) >> 4);
366 if (j <= 9)
367 phba->SerialNumber[i] =
368 (char)((uint8_t) 0x30 + (uint8_t) j);
369 else
370 phba->SerialNumber[i] =
371 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
372 i++;
373 j = (status & 0xf);
374 if (j <= 9)
375 phba->SerialNumber[i] =
376 (char)((uint8_t) 0x30 + (uint8_t) j);
377 else
378 phba->SerialNumber[i] =
379 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
380 }
381 }
382
dea31012005-04-17 16:05:31 -0500383 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500384 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500385 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500386 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400387 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500388 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500389 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500390 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500391 mempool_free( pmb, phba->mbox_mem_pool);
392 return -EIO;
393 }
394
395 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
396 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
397 phba->cfg_hba_queue_depth =
398 mb->un.varRdConfig.max_xri + 1;
399
400 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500401
402 /* Get the default values for Model Name and Description */
403 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
404
405 if ((phba->cfg_link_speed > LINK_SPEED_10G)
406 || ((phba->cfg_link_speed == LINK_SPEED_1G)
407 && !(phba->lmt & LMT_1Gb))
408 || ((phba->cfg_link_speed == LINK_SPEED_2G)
409 && !(phba->lmt & LMT_2Gb))
410 || ((phba->cfg_link_speed == LINK_SPEED_4G)
411 && !(phba->lmt & LMT_4Gb))
412 || ((phba->cfg_link_speed == LINK_SPEED_8G)
413 && !(phba->lmt & LMT_8Gb))
414 || ((phba->cfg_link_speed == LINK_SPEED_10G)
415 && !(phba->lmt & LMT_10Gb))) {
416 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500417 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400418 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500419 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500420 phba->cfg_link_speed);
421 phba->cfg_link_speed = LINK_SPEED_AUTO;
422 }
423
James Smart2e0fef82007-06-17 19:56:36 -0500424 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500425
James Smart0b727fe2007-10-27 13:37:25 -0400426 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500427 if (psli->ring[psli->extra_ring].cmdringaddr)
428 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500429 if (psli->ring[psli->fcp_ring].cmdringaddr)
430 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
431 if (psli->ring[psli->next_ring].cmdringaddr)
432 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
433
434 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500435 if (phba->sli_rev != 3)
436 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500437
James Smart93996272008-08-24 21:50:30 -0400438 /*
439 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
440 */
441 if (phba->intr_type == MSIX) {
442 rc = lpfc_config_msi(phba, pmb);
443 if (rc) {
444 mempool_free(pmb, phba->mbox_mem_pool);
445 return -EIO;
446 }
447 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
448 if (rc != MBX_SUCCESS) {
449 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
450 "0352 Config MSI mailbox command "
451 "failed, mbxCmd x%x, mbxStatus x%x\n",
452 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
453 mempool_free(pmb, phba->mbox_mem_pool);
454 return -EIO;
455 }
456 }
457
458 /* Initialize ERATT handling flag */
459 phba->hba_flag &= ~HBA_ERATT_HANDLED;
460
dea31012005-04-17 16:05:31 -0500461 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500462 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500463 status = readl(phba->HCregaddr);
464 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
465 if (psli->num_rings > 0)
466 status |= HC_R0INT_ENA;
467 if (psli->num_rings > 1)
468 status |= HC_R1INT_ENA;
469 if (psli->num_rings > 2)
470 status |= HC_R2INT_ENA;
471 if (psli->num_rings > 3)
472 status |= HC_R3INT_ENA;
473
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500474 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
475 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400476 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500477
dea31012005-04-17 16:05:31 -0500478 writel(status, phba->HCregaddr);
479 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500480 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500481
James Smart93996272008-08-24 21:50:30 -0400482 /* Set up ring-0 (ELS) timer */
483 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500484 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400485 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500486 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
487 phba->hb_outstanding = 0;
488 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400489 /* Set up error attention (ERATT) polling timer */
490 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500491
492 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
493 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400494 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400495 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400496 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400498 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500499 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500500 mb->mbxCommand, mb->mbxStatus);
501
502 /* Clear all interrupt enable conditions */
503 writel(0, phba->HCregaddr);
504 readl(phba->HCregaddr); /* flush */
505 /* Clear all pending interrupts */
506 writel(0xffffffff, phba->HAregaddr);
507 readl(phba->HAregaddr); /* flush */
508
James Smart2e0fef82007-06-17 19:56:36 -0500509 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400510 if (rc != MBX_BUSY)
511 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500512 return -EIO;
513 }
514 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400515 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
516 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
517 pmb->mbox_cmpl = lpfc_config_async_cmpl;
518 pmb->vport = phba->pport;
519 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500520
James Smart57127f12007-10-27 13:37:05 -0400521 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
522 lpfc_printf_log(phba,
523 KERN_ERR,
524 LOG_INIT,
525 "0456 Adapter failed to issue "
526 "ASYNCEVT_ENABLE mbox status x%x \n.",
527 rc);
528 mempool_free(pmb, phba->mbox_mem_pool);
529 }
James Smart97207482008-12-04 22:39:19 -0500530
531 /* Get Option rom version */
532 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
533 lpfc_dump_wakeup_param(phba, pmb);
534 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
535 pmb->vport = phba->pport;
536 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
537
538 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
539 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
540 "to get Option ROM version status x%x\n.", rc);
541 mempool_free(pmb, phba->mbox_mem_pool);
542 }
543
James Smartd7c255b2008-08-24 21:50:00 -0400544 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400545}
546
James Smarte59058c2008-08-24 21:49:00 -0400547/**
548 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
549 * @phba: pointer to lpfc HBA data structure.
550 *
551 * This routine will do LPFC uninitialization before the HBA is reset when
552 * bringing down the SLI Layer.
553 *
554 * Return codes
555 * 0 - success.
556 * Any other value - error.
557 **/
dea31012005-04-17 16:05:31 -0500558int
James Smart2e0fef82007-06-17 19:56:36 -0500559lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500560{
James Smart1b32f6a2008-02-08 18:49:39 -0500561 struct lpfc_vport **vports;
562 int i;
dea31012005-04-17 16:05:31 -0500563 /* Disable interrupts */
564 writel(0, phba->HCregaddr);
565 readl(phba->HCregaddr); /* flush */
566
James Smart1b32f6a2008-02-08 18:49:39 -0500567 if (phba->pport->load_flag & FC_UNLOADING)
568 lpfc_cleanup_discovery_resources(phba->pport);
569 else {
570 vports = lpfc_create_vport_work_array(phba);
571 if (vports != NULL)
572 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
573 lpfc_cleanup_discovery_resources(vports[i]);
574 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500575 }
576 return 0;
dea31012005-04-17 16:05:31 -0500577}
578
James Smarte59058c2008-08-24 21:49:00 -0400579/**
580 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
581 * @phba: pointer to lpfc HBA data structure.
582 *
583 * This routine will do uninitialization after the HBA is reset when bring
584 * down the SLI Layer.
585 *
586 * Return codes
587 * 0 - sucess.
588 * Any other value - error.
589 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500590int
James Smart2e0fef82007-06-17 19:56:36 -0500591lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500592{
593 struct lpfc_sli *psli = &phba->sli;
594 struct lpfc_sli_ring *pring;
595 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500596 struct lpfc_iocbq *iocb;
597 IOCB_t *cmd = NULL;
598 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500599 int i;
600
James Smart92d7f7b2007-06-17 19:56:38 -0500601 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
602 lpfc_sli_hbqbuf_free_all(phba);
603 else {
604 /* Cleanup preposted buffers on the ELS ring */
605 pring = &psli->ring[LPFC_ELS_RING];
606 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
607 list_del(&mp->list);
608 pring->postbufq_cnt--;
609 lpfc_mbuf_free(phba, mp->virt, mp->phys);
610 kfree(mp);
611 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500612 }
613
James Smart09372822008-01-11 01:52:54 -0500614 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500615 for (i = 0; i < psli->num_rings; i++) {
616 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500617
618 /* At this point in time the HBA is either reset or DOA. Either
619 * way, nothing should be on txcmplq as it will NEVER complete.
620 */
621 list_splice_init(&pring->txcmplq, &completions);
622 pring->txcmplq_cnt = 0;
623 spin_unlock_irq(&phba->hbalock);
624
625 while (!list_empty(&completions)) {
626 iocb = list_get_first(&completions, struct lpfc_iocbq,
627 list);
628 cmd = &iocb->iocb;
629 list_del_init(&iocb->list);
630
631 if (!iocb->iocb_cmpl)
632 lpfc_sli_release_iocbq(phba, iocb);
633 else {
634 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
635 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
636 (iocb->iocb_cmpl) (phba, iocb, iocb);
637 }
638 }
639
Jamie Wellnitz41415862006-02-28 19:25:27 -0500640 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500641 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500642 }
James Smart09372822008-01-11 01:52:54 -0500643 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500644
645 return 0;
646}
647
James Smarte59058c2008-08-24 21:49:00 -0400648/**
649 * lpfc_hb_timeout: The HBA-timer timeout handler.
650 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
651 *
652 * This is the HBA-timer timeout handler registered to the lpfc driver. When
653 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
654 * work-port-events bitmap and the worker thread is notified. This timeout
655 * event will be used by the worker thread to invoke the actual timeout
656 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
657 * be performed in the timeout handler and the HBA timeout event bit shall
658 * be cleared by the worker thread after it has taken the event bitmap out.
659 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100660static void
James Smart858c9f62007-06-17 19:56:39 -0500661lpfc_hb_timeout(unsigned long ptr)
662{
663 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400664 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500665 unsigned long iflag;
666
667 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400668
669 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500670 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400671 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
672 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500673 phba->pport->work_port_events |= WORKER_HB_TMO;
674 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
675
James Smart93996272008-08-24 21:50:30 -0400676 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400677 if (!tmo_posted)
678 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500679 return;
680}
681
James Smarte59058c2008-08-24 21:49:00 -0400682/**
683 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
684 * @phba: pointer to lpfc hba data structure.
685 * @pmboxq: pointer to the driver internal queue element for mailbox command.
686 *
687 * This is the callback function to the lpfc heart-beat mailbox command.
688 * If configured, the lpfc driver issues the heart-beat mailbox command to
689 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
690 * heart-beat mailbox command is issued, the driver shall set up heart-beat
691 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
692 * heart-beat outstanding state. Once the mailbox command comes back and
693 * no error conditions detected, the heart-beat mailbox command timer is
694 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
695 * state is cleared for the next heart-beat. If the timer expired with the
696 * heart-beat outstanding state set, the driver will put the HBA offline.
697 **/
James Smart858c9f62007-06-17 19:56:39 -0500698static void
699lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
700{
701 unsigned long drvr_flag;
702
703 spin_lock_irqsave(&phba->hbalock, drvr_flag);
704 phba->hb_outstanding = 0;
705 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
706
James Smart93996272008-08-24 21:50:30 -0400707 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -0500708 mempool_free(pmboxq, phba->mbox_mem_pool);
709 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
710 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400711 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500712 mod_timer(&phba->hb_tmofunc,
713 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
714 return;
715}
716
James Smarte59058c2008-08-24 21:49:00 -0400717/**
718 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
719 * @phba: pointer to lpfc hba data structure.
720 *
721 * This is the actual HBA-timer timeout handler to be invoked by the worker
722 * thread whenever the HBA timer fired and HBA-timeout event posted. This
723 * handler performs any periodic operations needed for the device. If such
724 * periodic event has already been attended to either in the interrupt handler
725 * or by processing slow-ring or fast-ring events within the HBA-timer
726 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
727 * the timer for the next timeout period. If lpfc heart-beat mailbox command
728 * is configured and there is no heart-beat mailbox command outstanding, a
729 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
730 * has been a heart-beat mailbox command outstanding, the HBA shall be put
731 * to offline.
732 **/
James Smart858c9f62007-06-17 19:56:39 -0500733void
734lpfc_hb_timeout_handler(struct lpfc_hba *phba)
735{
736 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500737 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500738 int retval;
739 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500740 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500741
742 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400743 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500744 (phba->pport->fc_flag & FC_OFFLINE_MODE))
745 return;
746
747 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -0500748
749 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
750 jiffies)) {
751 spin_unlock_irq(&phba->pport->work_port_lock);
752 if (!phba->hb_outstanding)
753 mod_timer(&phba->hb_tmofunc,
754 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
755 else
756 mod_timer(&phba->hb_tmofunc,
757 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
758 return;
759 }
760 spin_unlock_irq(&phba->pport->work_port_lock);
761
James Smart0ff10d42008-01-11 01:52:36 -0500762 if (phba->elsbuf_cnt &&
763 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
764 spin_lock_irq(&phba->hbalock);
765 list_splice_init(&phba->elsbuf, &completions);
766 phba->elsbuf_cnt = 0;
767 phba->elsbuf_prev_cnt = 0;
768 spin_unlock_irq(&phba->hbalock);
769
770 while (!list_empty(&completions)) {
771 list_remove_head(&completions, buf_ptr,
772 struct lpfc_dmabuf, list);
773 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
774 kfree(buf_ptr);
775 }
776 }
777 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
778
James Smart858c9f62007-06-17 19:56:39 -0500779 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500780 if (phba->cfg_enable_hba_heartbeat) {
781 if (!phba->hb_outstanding) {
782 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
783 if (!pmboxq) {
784 mod_timer(&phba->hb_tmofunc,
785 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
786 return;
787 }
788
789 lpfc_heart_beat(phba, pmboxq);
790 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
791 pmboxq->vport = phba->pport;
792 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
793
794 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
795 mempool_free(pmboxq, phba->mbox_mem_pool);
796 mod_timer(&phba->hb_tmofunc,
797 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
798 return;
799 }
James Smart858c9f62007-06-17 19:56:39 -0500800 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500801 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
802 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500803 return;
James Smart13815c82008-01-11 01:52:48 -0500804 } else {
805 /*
806 * If heart beat timeout called with hb_outstanding set
807 * we need to take the HBA offline.
808 */
809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
810 "0459 Adapter heartbeat failure, "
811 "taking this port offline.\n");
812
813 spin_lock_irq(&phba->hbalock);
814 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
815 spin_unlock_irq(&phba->hbalock);
816
817 lpfc_offline_prep(phba);
818 lpfc_offline(phba);
819 lpfc_unblock_mgmt_io(phba);
820 phba->link_state = LPFC_HBA_ERROR;
821 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500822 }
James Smart858c9f62007-06-17 19:56:39 -0500823 }
824}
825
James Smarte59058c2008-08-24 21:49:00 -0400826/**
827 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
828 * @phba: pointer to lpfc hba data structure.
829 *
830 * This routine is called to bring the HBA offline when HBA hardware error
831 * other than Port Error 6 has been detected.
832 **/
James Smart09372822008-01-11 01:52:54 -0500833static void
834lpfc_offline_eratt(struct lpfc_hba *phba)
835{
836 struct lpfc_sli *psli = &phba->sli;
837
838 spin_lock_irq(&phba->hbalock);
839 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
840 spin_unlock_irq(&phba->hbalock);
841 lpfc_offline_prep(phba);
842
843 lpfc_offline(phba);
844 lpfc_reset_barrier(phba);
845 lpfc_sli_brdreset(phba);
846 lpfc_hba_down_post(phba);
847 lpfc_sli_brdready(phba, HS_MBRDY);
848 lpfc_unblock_mgmt_io(phba);
849 phba->link_state = LPFC_HBA_ERROR;
850 return;
851}
852
James Smarte59058c2008-08-24 21:49:00 -0400853/**
854 * lpfc_handle_eratt: The HBA hardware error handler.
855 * @phba: pointer to lpfc hba data structure.
856 *
857 * This routine is invoked to handle the following HBA hardware error
858 * conditions:
859 * 1 - HBA error attention interrupt
860 * 2 - DMA ring index out of range
861 * 3 - Mailbox command came back as unknown
862 **/
dea31012005-04-17 16:05:31 -0500863void
James Smart2e0fef82007-06-17 19:56:36 -0500864lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500865{
James Smart2e0fef82007-06-17 19:56:36 -0500866 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500867 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500868 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400869 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400870 unsigned long temperature;
871 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500872 struct Scsi_Host *shost;
James Smartea2151b2008-09-07 11:52:10 -0400873 struct lpfc_board_event_header board_event;
James Smart2e0fef82007-06-17 19:56:36 -0500874
Linas Vepstas8d63f372007-02-14 14:28:36 -0600875 /* If the pci channel is offline, ignore possible errors,
876 * since we cannot communicate with the pci card anyway. */
877 if (pci_channel_offline(phba->pcidev))
878 return;
James Smart13815c82008-01-11 01:52:48 -0500879 /* If resets are disabled then leave the HBA alone and return */
880 if (!phba->cfg_enable_hba_reset)
881 return;
dea31012005-04-17 16:05:31 -0500882
James Smartea2151b2008-09-07 11:52:10 -0400883 /* Send an internal error event to mgmt application */
884 board_event.event_type = FC_REG_BOARD_EVENT;
885 board_event.subcategory = LPFC_EVENT_PORTINTERR;
886 shost = lpfc_shost_from_vport(phba->pport);
887 fc_host_post_vendor_event(shost, fc_get_event_number(),
888 sizeof(board_event),
889 (char *) &board_event,
James Smartddcc50f2008-12-04 22:38:46 -0500890 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400891
James Smart97eab632008-04-07 10:16:05 -0400892 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500893 /* Re-establishing Link */
894 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400895 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500896 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400897 phba->work_hs,
dea31012005-04-17 16:05:31 -0500898 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400899
James Smart92d7f7b2007-06-17 19:56:38 -0500900 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500901 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500902 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500903
904 /*
905 * Firmware stops when it triggled erratt with HS_FFER6.
906 * That could cause the I/Os dropped by the firmware.
907 * Error iocb (I/O) on txcmplq and let the SCSI layer
908 * retry it after re-establishing link.
909 */
910 pring = &psli->ring[psli->fcp_ring];
911 lpfc_sli_abort_iocb_ring(phba, pring);
912
dea31012005-04-17 16:05:31 -0500913 /*
914 * There was a firmware error. Take the hba offline and then
915 * attempt to restart it.
916 */
James Smart46fa3112007-04-25 09:51:45 -0400917 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500918 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500919 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500920 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400921 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500922 return;
923 }
James Smart46fa3112007-04-25 09:51:45 -0400924 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400925 } else if (phba->work_hs & HS_CRIT_TEMP) {
926 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
927 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
928 temp_event_data.event_code = LPFC_CRIT_TEMP;
929 temp_event_data.data = (uint32_t)temperature;
930
931 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -0400932 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -0400933 "(%ld), taking this port offline "
934 "Data: x%x x%x x%x\n",
935 temperature, phba->work_hs,
936 phba->work_status[0], phba->work_status[1]);
937
938 shost = lpfc_shost_from_vport(phba->pport);
939 fc_host_post_vendor_event(shost, fc_get_event_number(),
940 sizeof(temp_event_data),
941 (char *) &temp_event_data,
942 SCSI_NL_VID_TYPE_PCI
943 | PCI_VENDOR_ID_EMULEX);
944
James Smart7af67052007-10-27 13:38:11 -0400945 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400946 phba->over_temp_state = HBA_OVER_TEMP;
947 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500948 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400949
dea31012005-04-17 16:05:31 -0500950 } else {
951 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -0400952 * failure is a value other than FFER6. Do not call the offline
953 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -0500954 */
955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400956 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500957 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400958 phba->work_hs,
dea31012005-04-17 16:05:31 -0500959 phba->work_status[0], phba->work_status[1]);
960
James Smartd2873e42006-08-18 17:46:43 -0400961 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500962 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500963 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400964 sizeof(event_data), (char *) &event_data,
965 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
966
James Smart09372822008-01-11 01:52:54 -0500967 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500968 }
James Smart93996272008-08-24 21:50:30 -0400969 return;
dea31012005-04-17 16:05:31 -0500970}
971
James Smarte59058c2008-08-24 21:49:00 -0400972/**
973 * lpfc_handle_latt: The HBA link event handler.
974 * @phba: pointer to lpfc hba data structure.
975 *
976 * This routine is invoked from the worker thread to handle a HBA host
977 * attention link event.
978 **/
dea31012005-04-17 16:05:31 -0500979void
James Smart2e0fef82007-06-17 19:56:36 -0500980lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500981{
James Smart2e0fef82007-06-17 19:56:36 -0500982 struct lpfc_vport *vport = phba->pport;
983 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500984 LPFC_MBOXQ_t *pmb;
985 volatile uint32_t control;
986 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500987 int rc = 0;
dea31012005-04-17 16:05:31 -0500988
989 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500990 if (!pmb) {
991 rc = 1;
dea31012005-04-17 16:05:31 -0500992 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500993 }
dea31012005-04-17 16:05:31 -0500994
995 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500996 if (!mp) {
997 rc = 2;
dea31012005-04-17 16:05:31 -0500998 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500999 }
dea31012005-04-17 16:05:31 -05001000
1001 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001002 if (!mp->virt) {
1003 rc = 3;
dea31012005-04-17 16:05:31 -05001004 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001005 }
dea31012005-04-17 16:05:31 -05001006
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001007 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001008 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001009
1010 psli->slistat.link_event++;
1011 lpfc_read_la(phba, pmb, mp);
1012 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -05001013 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001014 /* Block ELS IOCBs until we have processed this mbox command */
1015 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001016 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001017 if (rc == MBX_NOT_FINISHED) {
1018 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001019 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001020 }
dea31012005-04-17 16:05:31 -05001021
1022 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001023 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001024 writel(HA_LATT, phba->HAregaddr);
1025 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001026 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001027
1028 return;
1029
James Smart14691152006-12-02 13:34:28 -05001030lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001031 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001032 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001033lpfc_handle_latt_free_mp:
1034 kfree(mp);
1035lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001036 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001037lpfc_handle_latt_err_exit:
1038 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001039 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001040 psli->sli_flag |= LPFC_PROCESS_LA;
1041 control = readl(phba->HCregaddr);
1042 control |= HC_LAINT_ENA;
1043 writel(control, phba->HCregaddr);
1044 readl(phba->HCregaddr); /* flush */
1045
1046 /* Clear Link Attention in HA REG */
1047 writel(HA_LATT, phba->HAregaddr);
1048 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001049 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001050 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001051 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001052
James Smart09372822008-01-11 01:52:54 -05001053 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1054 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001055
1056 return;
1057}
1058
James Smarte59058c2008-08-24 21:49:00 -04001059/**
1060 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
1061 * @phba: pointer to lpfc hba data structure.
1062 * @vpd: pointer to the vital product data.
1063 * @len: length of the vital product data in bytes.
1064 *
1065 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1066 * an array of characters. In this routine, the ModelName, ProgramType, and
1067 * ModelDesc, etc. fields of the phba data structure will be populated.
1068 *
1069 * Return codes
1070 * 0 - pointer to the VPD passed in is NULL
1071 * 1 - success
1072 **/
dea31012005-04-17 16:05:31 -05001073static int
James Smart2e0fef82007-06-17 19:56:36 -05001074lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001075{
1076 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001077 int Length;
dea31012005-04-17 16:05:31 -05001078 int i, j;
1079 int finished = 0;
1080 int index = 0;
1081
1082 if (!vpd)
1083 return 0;
1084
1085 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001087 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001088 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1089 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001090 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001091 switch (vpd[index]) {
1092 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001093 case 0x91:
dea31012005-04-17 16:05:31 -05001094 index += 1;
1095 lenlo = vpd[index];
1096 index += 1;
1097 lenhi = vpd[index];
1098 index += 1;
1099 i = ((((unsigned short)lenhi) << 8) + lenlo);
1100 index += i;
1101 break;
1102 case 0x90:
1103 index += 1;
1104 lenlo = vpd[index];
1105 index += 1;
1106 lenhi = vpd[index];
1107 index += 1;
1108 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001109 if (Length > len - index)
1110 Length = len - index;
dea31012005-04-17 16:05:31 -05001111 while (Length > 0) {
1112 /* Look for Serial Number */
1113 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1114 index += 2;
1115 i = vpd[index];
1116 index += 1;
1117 j = 0;
1118 Length -= (3+i);
1119 while(i--) {
1120 phba->SerialNumber[j++] = vpd[index++];
1121 if (j == 31)
1122 break;
1123 }
1124 phba->SerialNumber[j] = 0;
1125 continue;
1126 }
1127 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1128 phba->vpd_flag |= VPD_MODEL_DESC;
1129 index += 2;
1130 i = vpd[index];
1131 index += 1;
1132 j = 0;
1133 Length -= (3+i);
1134 while(i--) {
1135 phba->ModelDesc[j++] = vpd[index++];
1136 if (j == 255)
1137 break;
1138 }
1139 phba->ModelDesc[j] = 0;
1140 continue;
1141 }
1142 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1143 phba->vpd_flag |= VPD_MODEL_NAME;
1144 index += 2;
1145 i = vpd[index];
1146 index += 1;
1147 j = 0;
1148 Length -= (3+i);
1149 while(i--) {
1150 phba->ModelName[j++] = vpd[index++];
1151 if (j == 79)
1152 break;
1153 }
1154 phba->ModelName[j] = 0;
1155 continue;
1156 }
1157 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1158 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1159 index += 2;
1160 i = vpd[index];
1161 index += 1;
1162 j = 0;
1163 Length -= (3+i);
1164 while(i--) {
1165 phba->ProgramType[j++] = vpd[index++];
1166 if (j == 255)
1167 break;
1168 }
1169 phba->ProgramType[j] = 0;
1170 continue;
1171 }
1172 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1173 phba->vpd_flag |= VPD_PORT;
1174 index += 2;
1175 i = vpd[index];
1176 index += 1;
1177 j = 0;
1178 Length -= (3+i);
1179 while(i--) {
1180 phba->Port[j++] = vpd[index++];
1181 if (j == 19)
1182 break;
1183 }
1184 phba->Port[j] = 0;
1185 continue;
1186 }
1187 else {
1188 index += 2;
1189 i = vpd[index];
1190 index += 1;
1191 index += i;
1192 Length -= (3 + i);
1193 }
1194 }
1195 finished = 0;
1196 break;
1197 case 0x78:
1198 finished = 1;
1199 break;
1200 default:
1201 index ++;
1202 break;
1203 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001204 }
dea31012005-04-17 16:05:31 -05001205
1206 return(1);
1207}
1208
James Smarte59058c2008-08-24 21:49:00 -04001209/**
1210 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1211 * @phba: pointer to lpfc hba data structure.
1212 * @mdp: pointer to the data structure to hold the derived model name.
1213 * @descp: pointer to the data structure to hold the derived description.
1214 *
1215 * This routine retrieves HBA's description based on its registered PCI device
1216 * ID. The @descp passed into this function points to an array of 256 chars. It
1217 * shall be returned with the model name, maximum speed, and the host bus type.
1218 * The @mdp passed into this function points to an array of 80 chars. When the
1219 * function returns, the @mdp will be filled with the model name.
1220 **/
dea31012005-04-17 16:05:31 -05001221static void
James Smart2e0fef82007-06-17 19:56:36 -05001222lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001223{
1224 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001225 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001226 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001227 int GE = 0;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001228 struct {
1229 char * name;
1230 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001231 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001232 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001233
1234 if (mdp && mdp[0] != '\0'
1235 && descp && descp[0] != '\0')
1236 return;
1237
1238 if (phba->lmt & LMT_10Gb)
1239 max_speed = 10;
1240 else if (phba->lmt & LMT_8Gb)
1241 max_speed = 8;
1242 else if (phba->lmt & LMT_4Gb)
1243 max_speed = 4;
1244 else if (phba->lmt & LMT_2Gb)
1245 max_speed = 2;
1246 else
1247 max_speed = 1;
dea31012005-04-17 16:05:31 -05001248
1249 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001250
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001251 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001252 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001253 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001254 break;
dea31012005-04-17 16:05:31 -05001255 case PCI_DEVICE_ID_SUPERFLY:
1256 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001257 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001258 else
James Smart18a3b592006-12-02 13:35:08 -05001259 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001260 break;
1261 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001262 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001263 break;
1264 case PCI_DEVICE_ID_CENTAUR:
1265 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001266 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001267 else
James Smart18a3b592006-12-02 13:35:08 -05001268 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001269 break;
1270 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001271 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001272 break;
1273 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001274 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001275 break;
1276 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001277 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001278 break;
1279 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001280 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001281 break;
1282 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001283 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001284 break;
1285 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001286 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001287 break;
1288 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001289 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001290 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001291 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001292 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001293 break;
1294 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001295 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001296 break;
1297 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001298 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001299 break;
1300 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001301 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001302 break;
1303 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001304 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001305 break;
dea31012005-04-17 16:05:31 -05001306 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001307 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001308 break;
1309 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001310 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001311 break;
1312 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001313 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001314 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001315 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001316 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001317 break;
1318 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001319 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001320 break;
dea31012005-04-17 16:05:31 -05001321 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001322 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001323 break;
1324 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001325 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001326 break;
1327 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001328 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001329 break;
1330 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001331 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001332 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001333 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001334 m = (typeof(m)){"LP11000-S", max_speed,
1335 "PCI-X2"};
1336 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001337 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001338 m = (typeof(m)){"LPe11000-S", max_speed,
1339 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001340 break;
James Smartb87eab32007-04-25 09:53:28 -04001341 case PCI_DEVICE_ID_SAT:
1342 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1343 break;
1344 case PCI_DEVICE_ID_SAT_MID:
1345 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1346 break;
1347 case PCI_DEVICE_ID_SAT_SMB:
1348 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1349 break;
1350 case PCI_DEVICE_ID_SAT_DCSP:
1351 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1352 break;
1353 case PCI_DEVICE_ID_SAT_SCSP:
1354 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1355 break;
1356 case PCI_DEVICE_ID_SAT_S:
1357 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1358 break;
James Smart84774a42008-08-24 21:50:06 -04001359 case PCI_DEVICE_ID_HORNET:
1360 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1361 GE = 1;
1362 break;
1363 case PCI_DEVICE_ID_PROTEUS_VF:
1364 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1365 break;
1366 case PCI_DEVICE_ID_PROTEUS_PF:
1367 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1368 break;
1369 case PCI_DEVICE_ID_PROTEUS_S:
1370 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1371 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001372 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001373 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001374 break;
dea31012005-04-17 16:05:31 -05001375 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001376
1377 if (mdp && mdp[0] == '\0')
1378 snprintf(mdp, 79,"%s", m.name);
1379 if (descp && descp[0] == '\0')
1380 snprintf(descp, 255,
James Smart84774a42008-08-24 21:50:06 -04001381 "Emulex %s %d%s %s %s",
1382 m.name, m.max_speed,
1383 (GE) ? "GE" : "Gb",
1384 m.bus,
1385 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
dea31012005-04-17 16:05:31 -05001386}
1387
James Smarte59058c2008-08-24 21:49:00 -04001388/**
1389 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1390 * @phba: pointer to lpfc hba data structure.
1391 * @pring: pointer to a IOCB ring.
1392 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1393 *
1394 * This routine posts a given number of IOCBs with the associated DMA buffer
1395 * descriptors specified by the cnt argument to the given IOCB ring.
1396 *
1397 * Return codes
1398 * The number of IOCBs NOT able to be posted to the IOCB ring.
1399 **/
dea31012005-04-17 16:05:31 -05001400int
James Smart495a7142008-06-14 22:52:59 -04001401lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001402{
1403 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001404 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001405 struct lpfc_dmabuf *mp1, *mp2;
1406
1407 cnt += pring->missbufcnt;
1408
1409 /* While there are buffers to post */
1410 while (cnt > 0) {
1411 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001412 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001413 if (iocb == NULL) {
1414 pring->missbufcnt = cnt;
1415 return cnt;
1416 }
dea31012005-04-17 16:05:31 -05001417 icmd = &iocb->iocb;
1418
1419 /* 2 buffers can be posted per command */
1420 /* Allocate buffer to post */
1421 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1422 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001423 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1424 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001425 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001426 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001427 pring->missbufcnt = cnt;
1428 return cnt;
1429 }
1430
1431 INIT_LIST_HEAD(&mp1->list);
1432 /* Allocate buffer to post */
1433 if (cnt > 1) {
1434 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1435 if (mp2)
1436 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1437 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001438 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001439 kfree(mp2);
dea31012005-04-17 16:05:31 -05001440 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1441 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001442 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001443 pring->missbufcnt = cnt;
1444 return cnt;
1445 }
1446
1447 INIT_LIST_HEAD(&mp2->list);
1448 } else {
1449 mp2 = NULL;
1450 }
1451
1452 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1453 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1454 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1455 icmd->ulpBdeCount = 1;
1456 cnt--;
1457 if (mp2) {
1458 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1459 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1460 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1461 cnt--;
1462 icmd->ulpBdeCount = 2;
1463 }
1464
1465 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1466 icmd->ulpLe = 1;
1467
dea31012005-04-17 16:05:31 -05001468 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1469 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1470 kfree(mp1);
1471 cnt++;
1472 if (mp2) {
1473 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1474 kfree(mp2);
1475 cnt++;
1476 }
James Bottomley604a3e32005-10-29 10:28:33 -05001477 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001478 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001479 return cnt;
1480 }
dea31012005-04-17 16:05:31 -05001481 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001482 if (mp2)
dea31012005-04-17 16:05:31 -05001483 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001484 }
1485 pring->missbufcnt = 0;
1486 return 0;
1487}
1488
James Smarte59058c2008-08-24 21:49:00 -04001489/**
1490 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1491 * @phba: pointer to lpfc hba data structure.
1492 *
1493 * This routine posts initial receive IOCB buffers to the ELS ring. The
1494 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1495 * set to 64 IOCBs.
1496 *
1497 * Return codes
1498 * 0 - success (currently always success)
1499 **/
dea31012005-04-17 16:05:31 -05001500static int
James Smart2e0fef82007-06-17 19:56:36 -05001501lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001502{
1503 struct lpfc_sli *psli = &phba->sli;
1504
1505 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001506 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001507 /* Ring 2 - FCP no buffers needed */
1508
1509 return 0;
1510}
1511
1512#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1513
James Smarte59058c2008-08-24 21:49:00 -04001514/**
1515 * lpfc_sha_init: Set up initial array of hash table entries.
1516 * @HashResultPointer: pointer to an array as hash table.
1517 *
1518 * This routine sets up the initial values to the array of hash table entries
1519 * for the LC HBAs.
1520 **/
dea31012005-04-17 16:05:31 -05001521static void
1522lpfc_sha_init(uint32_t * HashResultPointer)
1523{
1524 HashResultPointer[0] = 0x67452301;
1525 HashResultPointer[1] = 0xEFCDAB89;
1526 HashResultPointer[2] = 0x98BADCFE;
1527 HashResultPointer[3] = 0x10325476;
1528 HashResultPointer[4] = 0xC3D2E1F0;
1529}
1530
James Smarte59058c2008-08-24 21:49:00 -04001531/**
1532 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1533 * @HashResultPointer: pointer to an initial/result hash table.
1534 * @HashWorkingPointer: pointer to an working hash table.
1535 *
1536 * This routine iterates an initial hash table pointed by @HashResultPointer
1537 * with the values from the working hash table pointeed by @HashWorkingPointer.
1538 * The results are putting back to the initial hash table, returned through
1539 * the @HashResultPointer as the result hash table.
1540 **/
dea31012005-04-17 16:05:31 -05001541static void
1542lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1543{
1544 int t;
1545 uint32_t TEMP;
1546 uint32_t A, B, C, D, E;
1547 t = 16;
1548 do {
1549 HashWorkingPointer[t] =
1550 S(1,
1551 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1552 8] ^
1553 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1554 } while (++t <= 79);
1555 t = 0;
1556 A = HashResultPointer[0];
1557 B = HashResultPointer[1];
1558 C = HashResultPointer[2];
1559 D = HashResultPointer[3];
1560 E = HashResultPointer[4];
1561
1562 do {
1563 if (t < 20) {
1564 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1565 } else if (t < 40) {
1566 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1567 } else if (t < 60) {
1568 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1569 } else {
1570 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1571 }
1572 TEMP += S(5, A) + E + HashWorkingPointer[t];
1573 E = D;
1574 D = C;
1575 C = S(30, B);
1576 B = A;
1577 A = TEMP;
1578 } while (++t <= 79);
1579
1580 HashResultPointer[0] += A;
1581 HashResultPointer[1] += B;
1582 HashResultPointer[2] += C;
1583 HashResultPointer[3] += D;
1584 HashResultPointer[4] += E;
1585
1586}
1587
James Smarte59058c2008-08-24 21:49:00 -04001588/**
1589 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1590 * @RandomChallenge: pointer to the entry of host challenge random number array.
1591 * @HashWorking: pointer to the entry of the working hash array.
1592 *
1593 * This routine calculates the working hash array referred by @HashWorking
1594 * from the challenge random numbers associated with the host, referred by
1595 * @RandomChallenge. The result is put into the entry of the working hash
1596 * array and returned by reference through @HashWorking.
1597 **/
dea31012005-04-17 16:05:31 -05001598static void
1599lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1600{
1601 *HashWorking = (*RandomChallenge ^ *HashWorking);
1602}
1603
James Smarte59058c2008-08-24 21:49:00 -04001604/**
1605 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1606 * @phba: pointer to lpfc hba data structure.
1607 * @hbainit: pointer to an array of unsigned 32-bit integers.
1608 *
1609 * This routine performs the special handling for LC HBA initialization.
1610 **/
dea31012005-04-17 16:05:31 -05001611void
1612lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1613{
1614 int t;
1615 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001616 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001617
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001618 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001619 if (!HashWorking)
1620 return;
1621
dea31012005-04-17 16:05:31 -05001622 HashWorking[0] = HashWorking[78] = *pwwnn++;
1623 HashWorking[1] = HashWorking[79] = *pwwnn;
1624
1625 for (t = 0; t < 7; t++)
1626 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1627
1628 lpfc_sha_init(hbainit);
1629 lpfc_sha_iterate(hbainit, HashWorking);
1630 kfree(HashWorking);
1631}
1632
James Smarte59058c2008-08-24 21:49:00 -04001633/**
1634 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1635 * @vport: pointer to a virtual N_Port data structure.
1636 *
1637 * This routine performs the necessary cleanups before deleting the @vport.
1638 * It invokes the discovery state machine to perform necessary state
1639 * transitions and to release the ndlps associated with the @vport. Note,
1640 * the physical port is treated as @vport 0.
1641 **/
James Smart87af33f2007-10-27 13:37:43 -04001642void
James Smart2e0fef82007-06-17 19:56:36 -05001643lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001644{
James Smart87af33f2007-10-27 13:37:43 -04001645 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001646 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001647 int i = 0;
dea31012005-04-17 16:05:31 -05001648
James Smart87af33f2007-10-27 13:37:43 -04001649 if (phba->link_state > LPFC_LINK_DOWN)
1650 lpfc_port_link_failure(vport);
1651
1652 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001653 if (!NLP_CHK_NODE_ACT(ndlp)) {
1654 ndlp = lpfc_enable_node(vport, ndlp,
1655 NLP_STE_UNUSED_NODE);
1656 if (!ndlp)
1657 continue;
1658 spin_lock_irq(&phba->ndlp_lock);
1659 NLP_SET_FREE_REQ(ndlp);
1660 spin_unlock_irq(&phba->ndlp_lock);
1661 /* Trigger the release of the ndlp memory */
1662 lpfc_nlp_put(ndlp);
1663 continue;
1664 }
1665 spin_lock_irq(&phba->ndlp_lock);
1666 if (NLP_CHK_FREE_REQ(ndlp)) {
1667 /* The ndlp should not be in memory free mode already */
1668 spin_unlock_irq(&phba->ndlp_lock);
1669 continue;
1670 } else
1671 /* Indicate request for freeing ndlp memory */
1672 NLP_SET_FREE_REQ(ndlp);
1673 spin_unlock_irq(&phba->ndlp_lock);
1674
James Smart58da1ff2008-04-07 10:15:56 -04001675 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1676 ndlp->nlp_DID == Fabric_DID) {
1677 /* Just free up ndlp with Fabric_DID for vports */
1678 lpfc_nlp_put(ndlp);
1679 continue;
1680 }
1681
James Smart87af33f2007-10-27 13:37:43 -04001682 if (ndlp->nlp_type & NLP_FABRIC)
1683 lpfc_disc_state_machine(vport, ndlp, NULL,
1684 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001685
James Smart87af33f2007-10-27 13:37:43 -04001686 lpfc_disc_state_machine(vport, ndlp, NULL,
1687 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001688
James Smart87af33f2007-10-27 13:37:43 -04001689 }
1690
James Smarta8adb832007-10-27 13:37:53 -04001691 /* At this point, ALL ndlp's should be gone
1692 * because of the previous NLP_EVT_DEVICE_RM.
1693 * Lets wait for this to happen, if needed.
1694 */
James Smart87af33f2007-10-27 13:37:43 -04001695 while (!list_empty(&vport->fc_nodes)) {
1696
James Smarta8adb832007-10-27 13:37:53 -04001697 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001698 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001699 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001700 list_for_each_entry_safe(ndlp, next_ndlp,
1701 &vport->fc_nodes, nlp_listp) {
1702 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1703 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001704 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001705 "usgmap:x%x refcnt:%d\n",
1706 ndlp->nlp_DID, (void *)ndlp,
1707 ndlp->nlp_usg_map,
1708 atomic_read(
1709 &ndlp->kref.refcount));
1710 }
James Smarta8adb832007-10-27 13:37:53 -04001711 break;
James Smart87af33f2007-10-27 13:37:43 -04001712 }
James Smarta8adb832007-10-27 13:37:53 -04001713
1714 /* Wait for any activity on ndlps to settle */
1715 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001716 }
dea31012005-04-17 16:05:31 -05001717 return;
1718}
1719
James Smarte59058c2008-08-24 21:49:00 -04001720/**
1721 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1722 * @vport: pointer to a virtual N_Port data structure.
1723 *
1724 * This routine stops all the timers associated with a @vport. This function
1725 * is invoked before disabling or deleting a @vport. Note that the physical
1726 * port is treated as @vport 0.
1727 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001728void
1729lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001730{
James Smart92d7f7b2007-06-17 19:56:38 -05001731 del_timer_sync(&vport->els_tmofunc);
1732 del_timer_sync(&vport->fc_fdmitmo);
1733 lpfc_can_disctmo(vport);
1734 return;
dea31012005-04-17 16:05:31 -05001735}
1736
James Smarte59058c2008-08-24 21:49:00 -04001737/**
1738 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1739 * @phba: pointer to lpfc hba data structure.
1740 *
1741 * This routine stops all the timers associated with a HBA. This function is
1742 * invoked before either putting a HBA offline or unloading the driver.
1743 **/
James Smart2e0fef82007-06-17 19:56:36 -05001744static void
James Smart92d7f7b2007-06-17 19:56:38 -05001745lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001746{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001747 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001748 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001749 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001750 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001751 phba->hb_outstanding = 0;
1752 del_timer_sync(&phba->hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001753 del_timer_sync(&phba->eratt_poll);
James Smart2e0fef82007-06-17 19:56:36 -05001754 return;
dea31012005-04-17 16:05:31 -05001755}
1756
James Smarte59058c2008-08-24 21:49:00 -04001757/**
1758 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1759 * @phba: pointer to lpfc hba data structure.
1760 *
1761 * This routine marks a HBA's management interface as blocked. Once the HBA's
1762 * management interface is marked as blocked, all the user space access to
1763 * the HBA, whether they are from sysfs interface or libdfc interface will
1764 * all be blocked. The HBA is set to block the management interface when the
1765 * driver prepares the HBA interface for online or offline.
1766 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001767static void
1768lpfc_block_mgmt_io(struct lpfc_hba * phba)
1769{
1770 unsigned long iflag;
1771
1772 spin_lock_irqsave(&phba->hbalock, iflag);
1773 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1774 spin_unlock_irqrestore(&phba->hbalock, iflag);
1775}
1776
James Smarte59058c2008-08-24 21:49:00 -04001777/**
1778 * lpfc_online: Initialize and bring a HBA online.
1779 * @phba: pointer to lpfc hba data structure.
1780 *
1781 * This routine initializes the HBA and brings a HBA online. During this
1782 * process, the management interface is blocked to prevent user space access
1783 * to the HBA interfering with the driver initialization.
1784 *
1785 * Return codes
1786 * 0 - successful
1787 * 1 - failed
1788 **/
dea31012005-04-17 16:05:31 -05001789int
James Smart2e0fef82007-06-17 19:56:36 -05001790lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001791{
James Smart2e0fef82007-06-17 19:56:36 -05001792 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001793 struct lpfc_vport **vports;
1794 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001795
dea31012005-04-17 16:05:31 -05001796 if (!phba)
1797 return 0;
1798
James Smart2e0fef82007-06-17 19:56:36 -05001799 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001800 return 0;
1801
James Smarted957682007-06-17 19:56:37 -05001802 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001803 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001804
James Smart46fa3112007-04-25 09:51:45 -04001805 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001806
James Smart46fa3112007-04-25 09:51:45 -04001807 if (!lpfc_sli_queue_setup(phba)) {
1808 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001809 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001810 }
1811
1812 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1813 lpfc_unblock_mgmt_io(phba);
1814 return 1;
1815 }
dea31012005-04-17 16:05:31 -05001816
James Smart549e55c2007-08-02 11:09:51 -04001817 vports = lpfc_create_vport_work_array(phba);
1818 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001819 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001820 struct Scsi_Host *shost;
1821 shost = lpfc_shost_from_vport(vports[i]);
1822 spin_lock_irq(shost->host_lock);
1823 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1824 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1825 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1826 spin_unlock_irq(shost->host_lock);
1827 }
James Smart09372822008-01-11 01:52:54 -05001828 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001829
James Smart46fa3112007-04-25 09:51:45 -04001830 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001831 return 0;
1832}
1833
James Smarte59058c2008-08-24 21:49:00 -04001834/**
1835 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1836 * @phba: pointer to lpfc hba data structure.
1837 *
1838 * This routine marks a HBA's management interface as not blocked. Once the
1839 * HBA's management interface is marked as not blocked, all the user space
1840 * access to the HBA, whether they are from sysfs interface or libdfc
1841 * interface will be allowed. The HBA is set to block the management interface
1842 * when the driver prepares the HBA interface for online or offline and then
1843 * set to unblock the management interface afterwards.
1844 **/
James Smart46fa3112007-04-25 09:51:45 -04001845void
James Smart46fa3112007-04-25 09:51:45 -04001846lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1847{
1848 unsigned long iflag;
1849
James Smart2e0fef82007-06-17 19:56:36 -05001850 spin_lock_irqsave(&phba->hbalock, iflag);
1851 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1852 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001853}
1854
James Smarte59058c2008-08-24 21:49:00 -04001855/**
1856 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1857 * @phba: pointer to lpfc hba data structure.
1858 *
1859 * This routine is invoked to prepare a HBA to be brought offline. It performs
1860 * unregistration login to all the nodes on all vports and flushes the mailbox
1861 * queue to make it ready to be brought offline.
1862 **/
James Smart46fa3112007-04-25 09:51:45 -04001863void
1864lpfc_offline_prep(struct lpfc_hba * phba)
1865{
James Smart2e0fef82007-06-17 19:56:36 -05001866 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001867 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001868 struct lpfc_vport **vports;
1869 int i;
dea31012005-04-17 16:05:31 -05001870
James Smart2e0fef82007-06-17 19:56:36 -05001871 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001872 return;
dea31012005-04-17 16:05:31 -05001873
James Smart46fa3112007-04-25 09:51:45 -04001874 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001875
1876 lpfc_linkdown(phba);
1877
James Smart87af33f2007-10-27 13:37:43 -04001878 /* Issue an unreg_login to all nodes on all vports */
1879 vports = lpfc_create_vport_work_array(phba);
1880 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001881 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001882 struct Scsi_Host *shost;
1883
James Smarta8adb832007-10-27 13:37:53 -04001884 if (vports[i]->load_flag & FC_UNLOADING)
1885 continue;
James Smart87af33f2007-10-27 13:37:43 -04001886 shost = lpfc_shost_from_vport(vports[i]);
1887 list_for_each_entry_safe(ndlp, next_ndlp,
1888 &vports[i]->fc_nodes,
1889 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001890 if (!NLP_CHK_NODE_ACT(ndlp))
1891 continue;
James Smart87af33f2007-10-27 13:37:43 -04001892 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1893 continue;
1894 if (ndlp->nlp_type & NLP_FABRIC) {
1895 lpfc_disc_state_machine(vports[i], ndlp,
1896 NULL, NLP_EVT_DEVICE_RECOVERY);
1897 lpfc_disc_state_machine(vports[i], ndlp,
1898 NULL, NLP_EVT_DEVICE_RM);
1899 }
1900 spin_lock_irq(shost->host_lock);
1901 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1902 spin_unlock_irq(shost->host_lock);
1903 lpfc_unreg_rpi(vports[i], ndlp);
1904 }
1905 }
1906 }
James Smart09372822008-01-11 01:52:54 -05001907 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001908
James Smart46fa3112007-04-25 09:51:45 -04001909 lpfc_sli_flush_mbox_queue(phba);
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
1913 * lpfc_offline: Bring a HBA offline.
1914 * @phba: pointer to lpfc hba data structure.
1915 *
1916 * This routine actually brings a HBA offline. It stops all the timers
1917 * associated with the HBA, brings down the SLI layer, and eventually
1918 * marks the HBA as in offline state for the upper layer protocol.
1919 **/
James Smart46fa3112007-04-25 09:51:45 -04001920void
James Smart2e0fef82007-06-17 19:56:36 -05001921lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001922{
James Smart549e55c2007-08-02 11:09:51 -04001923 struct Scsi_Host *shost;
1924 struct lpfc_vport **vports;
1925 int i;
James Smart46fa3112007-04-25 09:51:45 -04001926
James Smart549e55c2007-08-02 11:09:51 -04001927 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001928 return;
James Smart688a8862006-07-06 15:49:56 -04001929
dea31012005-04-17 16:05:31 -05001930 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001931 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001932 vports = lpfc_create_vport_work_array(phba);
1933 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001934 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001935 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001936 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001937 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001938 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001939 /* Bring down the SLI Layer and cleanup. The HBA is offline
1940 now. */
1941 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001942 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001943 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001944 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001945 vports = lpfc_create_vport_work_array(phba);
1946 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001947 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001948 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001949 spin_lock_irq(shost->host_lock);
1950 vports[i]->work_port_events = 0;
1951 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1952 spin_unlock_irq(shost->host_lock);
1953 }
James Smart09372822008-01-11 01:52:54 -05001954 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001955}
1956
James Smarte59058c2008-08-24 21:49:00 -04001957/**
1958 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1959 * @phba: pointer to lpfc hba data structure.
1960 *
1961 * This routine is to free all the SCSI buffers and IOCBs from the driver
1962 * list back to kernel. It is called from lpfc_pci_remove_one to free
1963 * the internal resources before the device is removed from the system.
1964 *
1965 * Return codes
1966 * 0 - successful (for now, it always returns 0)
1967 **/
dea31012005-04-17 16:05:31 -05001968static int
James Smart2e0fef82007-06-17 19:56:36 -05001969lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001970{
1971 struct lpfc_scsi_buf *sb, *sb_next;
1972 struct lpfc_iocbq *io, *io_next;
1973
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001975 /* Release all the lpfc_scsi_bufs maintained by this host. */
1976 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1977 list_del(&sb->list);
1978 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001979 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001980 kfree(sb);
1981 phba->total_scsi_bufs--;
1982 }
1983
1984 /* Release all the lpfc_iocbq entries maintained by this host. */
1985 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1986 list_del(&io->list);
1987 kfree(io);
1988 phba->total_iocbq_bufs--;
1989 }
1990
James Smart2e0fef82007-06-17 19:56:36 -05001991 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001992
1993 return 0;
1994}
1995
James Smarte59058c2008-08-24 21:49:00 -04001996/**
1997 * lpfc_create_port: Create an FC port.
1998 * @phba: pointer to lpfc hba data structure.
1999 * @instance: a unique integer ID to this FC port.
2000 * @dev: pointer to the device data structure.
2001 *
2002 * This routine creates a FC port for the upper layer protocol. The FC port
2003 * can be created on top of either a physical port or a virtual port provided
2004 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2005 * and associates the FC port created before adding the shost into the SCSI
2006 * layer.
2007 *
2008 * Return codes
2009 * @vport - pointer to the virtual N_Port data structure.
2010 * NULL - port create failed.
2011 **/
James Smart2e0fef82007-06-17 19:56:36 -05002012struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002013lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002014{
James Smart2e0fef82007-06-17 19:56:36 -05002015 struct lpfc_vport *vport;
2016 struct Scsi_Host *shost;
2017 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002018
James Smart3de2a652007-08-02 11:09:59 -04002019 if (dev != &phba->pcidev->dev)
2020 shost = scsi_host_alloc(&lpfc_vport_template,
2021 sizeof(struct lpfc_vport));
2022 else
2023 shost = scsi_host_alloc(&lpfc_template,
2024 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002025 if (!shost)
2026 goto out;
James Smart47a86172007-04-25 09:53:22 -04002027
James Smart2e0fef82007-06-17 19:56:36 -05002028 vport = (struct lpfc_vport *) shost->hostdata;
2029 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002030 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002031 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002032 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002033
James Smart3de2a652007-08-02 11:09:59 -04002034 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002035 shost->unique_id = instance;
2036 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002037 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002038 shost->this_id = -1;
2039 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04002040 /*
James Smart2e0fef82007-06-17 19:56:36 -05002041 * Set initial can_queue value since 0 is no longer supported and
2042 * scsi_add_host will fail. This will be adjusted later based on the
2043 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002044 */
James Smart2e0fef82007-06-17 19:56:36 -05002045 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002046 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002047 shost->transportt = lpfc_vport_transport_template;
2048 vport->port_type = LPFC_NPIV_PORT;
2049 } else {
2050 shost->transportt = lpfc_transport_template;
2051 vport->port_type = LPFC_PHYSICAL_PORT;
2052 }
James Smart47a86172007-04-25 09:53:22 -04002053
James Smart2e0fef82007-06-17 19:56:36 -05002054 /* Initialize all internally managed lists. */
2055 INIT_LIST_HEAD(&vport->fc_nodes);
2056 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002057
James Smart2e0fef82007-06-17 19:56:36 -05002058 init_timer(&vport->fc_disctmo);
2059 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002060 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002061
James Smart2e0fef82007-06-17 19:56:36 -05002062 init_timer(&vport->fc_fdmitmo);
2063 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002064 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002065
James Smart2e0fef82007-06-17 19:56:36 -05002066 init_timer(&vport->els_tmofunc);
2067 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002068 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002069
James Smart3de2a652007-08-02 11:09:59 -04002070 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05002071 if (error)
2072 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002073
James Smart549e55c2007-08-02 11:09:51 -04002074 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002075 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002076 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002077 return vport;
James Smart47a86172007-04-25 09:53:22 -04002078
James Smart2e0fef82007-06-17 19:56:36 -05002079out_put_shost:
2080 scsi_host_put(shost);
2081out:
2082 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002083}
2084
James Smarte59058c2008-08-24 21:49:00 -04002085/**
2086 * destroy_port: Destroy an FC port.
2087 * @vport: pointer to an lpfc virtual N_Port data structure.
2088 *
2089 * This routine destroys a FC port from the upper layer protocol. All the
2090 * resources associated with the port are released.
2091 **/
James Smart2e0fef82007-06-17 19:56:36 -05002092void
2093destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002094{
James Smart92d7f7b2007-06-17 19:56:38 -05002095 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2096 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002097
James Smart858c9f62007-06-17 19:56:39 -05002098 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002099 fc_remove_host(shost);
2100 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002101
James Smart92d7f7b2007-06-17 19:56:38 -05002102 spin_lock_irq(&phba->hbalock);
2103 list_del_init(&vport->listentry);
2104 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002105
James Smart92d7f7b2007-06-17 19:56:38 -05002106 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002107 return;
James Smart47a86172007-04-25 09:53:22 -04002108}
2109
James Smarte59058c2008-08-24 21:49:00 -04002110/**
2111 * lpfc_get_instance: Get a unique integer ID.
2112 *
2113 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2114 * uses the kernel idr facility to perform the task.
2115 *
2116 * Return codes:
2117 * instance - a unique integer ID allocated as the new instance.
2118 * -1 - lpfc get instance failed.
2119 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002120int
2121lpfc_get_instance(void)
2122{
2123 int instance = 0;
2124
2125 /* Assign an unused number */
2126 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2127 return -1;
2128 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2129 return -1;
2130 return instance;
2131}
2132
James Smarte59058c2008-08-24 21:49:00 -04002133/**
2134 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2135 * @shost: pointer to SCSI host data structure.
2136 * @time: elapsed time of the scan in jiffies.
2137 *
2138 * This routine is called by the SCSI layer with a SCSI host to determine
2139 * whether the scan host is finished.
2140 *
2141 * Note: there is no scan_start function as adapter initialization will have
2142 * asynchronously kicked off the link initialization.
2143 *
2144 * Return codes
2145 * 0 - SCSI host scan is not over yet.
2146 * 1 - SCSI host scan is over.
2147 **/
James Smart47a86172007-04-25 09:53:22 -04002148int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2149{
James Smart2e0fef82007-06-17 19:56:36 -05002150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2151 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002152 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002153
James Smart858c9f62007-06-17 19:56:39 -05002154 spin_lock_irq(shost->host_lock);
2155
James Smart51ef4c22007-08-02 11:10:31 -04002156 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002157 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002158 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002159 }
James Smart2e0fef82007-06-17 19:56:36 -05002160 if (time >= 30 * HZ) {
2161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002162 "0461 Scanning longer than 30 "
2163 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002164 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002165 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002166 }
2167 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2168 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002169 "0465 Link down longer than 15 "
2170 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002171 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002172 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002173 }
2174
James Smart2e0fef82007-06-17 19:56:36 -05002175 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002176 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002177 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002178 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002179 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002180 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002181 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002182 goto finished;
2183
2184 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002185
2186finished:
James Smart858c9f62007-06-17 19:56:39 -05002187 spin_unlock_irq(shost->host_lock);
2188 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002189}
2190
James Smarte59058c2008-08-24 21:49:00 -04002191/**
2192 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2193 * @shost: pointer to SCSI host data structure.
2194 *
2195 * This routine initializes a given SCSI host attributes on a FC port. The
2196 * SCSI host can be either on top of a physical port or a virtual port.
2197 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002198void lpfc_host_attrib_init(struct Scsi_Host *shost)
2199{
2200 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2201 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002202 /*
James Smart2e0fef82007-06-17 19:56:36 -05002203 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002204 */
2205
James Smart2e0fef82007-06-17 19:56:36 -05002206 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2207 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002208 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2209
2210 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002211 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002212 fc_host_supported_fc4s(shost)[2] = 1;
2213 fc_host_supported_fc4s(shost)[7] = 1;
2214
James Smart92d7f7b2007-06-17 19:56:38 -05002215 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2216 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002217
2218 fc_host_supported_speeds(shost) = 0;
2219 if (phba->lmt & LMT_10Gb)
2220 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002221 if (phba->lmt & LMT_8Gb)
2222 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002223 if (phba->lmt & LMT_4Gb)
2224 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2225 if (phba->lmt & LMT_2Gb)
2226 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2227 if (phba->lmt & LMT_1Gb)
2228 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2229
2230 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002231 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2232 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002233
2234 /* This value is also unchanging */
2235 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002236 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002237 fc_host_active_fc4s(shost)[2] = 1;
2238 fc_host_active_fc4s(shost)[7] = 1;
2239
James Smart92d7f7b2007-06-17 19:56:38 -05002240 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002241 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002242 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002243 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002244}
dea31012005-04-17 16:05:31 -05002245
James Smarte59058c2008-08-24 21:49:00 -04002246/**
2247 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2248 * @phba: pointer to lpfc hba data structure.
2249 *
2250 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2251 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2252 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2253 * on the current availability of PCI vector resources. The device driver is
2254 * responsible for calling the individual request_irq() to register each MSI-X
2255 * vector with a interrupt handler, which is done in this function. Note that
2256 * later when device is unloading, the driver should always call free_irq()
2257 * on all MSI-X vectors it has done request_irq() on before calling
2258 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2259 * will be left with MSI-X enabled and leaks its vectors.
2260 *
2261 * Return codes
2262 * 0 - sucessful
2263 * other values - error
2264 **/
James Smartdb2378e2008-02-08 18:49:51 -05002265static int
2266lpfc_enable_msix(struct lpfc_hba *phba)
2267{
James Smart93996272008-08-24 21:50:30 -04002268 int rc, i;
2269 LPFC_MBOXQ_t *pmb;
James Smartdb2378e2008-02-08 18:49:51 -05002270
James Smart93996272008-08-24 21:50:30 -04002271 /* Set up MSI-X multi-message vectors */
2272 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2273 phba->msix_entries[i].entry = i;
James Smartdb2378e2008-02-08 18:49:51 -05002274
James Smart93996272008-08-24 21:50:30 -04002275 /* Configure MSI-X capability structure */
2276 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
James Smartdb2378e2008-02-08 18:49:51 -05002277 ARRAY_SIZE(phba->msix_entries));
James Smart93996272008-08-24 21:50:30 -04002278 if (rc) {
James Smartdb2378e2008-02-08 18:49:51 -05002279 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05002280 "0420 PCI enable MSI-X failed (%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002281 goto msi_fail_out;
2282 } else
2283 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2284 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2285 "0477 MSI-X entry[%d]: vector=x%x "
2286 "message=%d\n", i,
2287 phba->msix_entries[i].vector,
2288 phba->msix_entries[i].entry);
2289 /*
2290 * Assign MSI-X vectors to interrupt handlers
2291 */
2292
2293 /* vector-0 is associated to slow-path handler */
2294 rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler,
2295 IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba);
2296 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002297 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002298 "0421 MSI-X slow-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002299 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002300 goto msi_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002301 }
2302
James Smart93996272008-08-24 21:50:30 -04002303 /* vector-1 is associated to fast-path handler */
2304 rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler,
2305 IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba);
2306
2307 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002308 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002309 "0429 MSI-X fast-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002310 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002311 goto irq_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002312 }
James Smart93996272008-08-24 21:50:30 -04002313
2314 /*
2315 * Configure HBA MSI-X attention conditions to messages
2316 */
2317 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2318
2319 if (!pmb) {
2320 rc = -ENOMEM;
2321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2322 "0474 Unable to allocate memory for issuing "
2323 "MBOX_CONFIG_MSI command\n");
2324 goto mem_fail_out;
2325 }
2326 rc = lpfc_config_msi(phba, pmb);
2327 if (rc)
2328 goto mbx_fail_out;
2329 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2330 if (rc != MBX_SUCCESS) {
James Smart5b75da22008-12-04 22:39:35 -05002331 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smart93996272008-08-24 21:50:30 -04002332 "0351 Config MSI mailbox command failed, "
2333 "mbxCmd x%x, mbxStatus x%x\n",
2334 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
2335 goto mbx_fail_out;
2336 }
2337
2338 /* Free memory allocated for mailbox command */
2339 mempool_free(pmb, phba->mbox_mem_pool);
2340 return rc;
2341
2342mbx_fail_out:
2343 /* Free memory allocated for mailbox command */
2344 mempool_free(pmb, phba->mbox_mem_pool);
2345
2346mem_fail_out:
2347 /* free the irq already requested */
2348 free_irq(phba->msix_entries[1].vector, phba);
2349
2350irq_fail_out:
2351 /* free the irq already requested */
2352 free_irq(phba->msix_entries[0].vector, phba);
2353
2354msi_fail_out:
2355 /* Unconfigure MSI-X capability structure */
2356 pci_disable_msix(phba->pcidev);
2357 return rc;
James Smartdb2378e2008-02-08 18:49:51 -05002358}
2359
James Smarte59058c2008-08-24 21:49:00 -04002360/**
2361 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2362 * @phba: pointer to lpfc hba data structure.
2363 *
2364 * This routine is invoked to release the MSI-X vectors and then disable the
2365 * MSI-X interrupt mode.
2366 **/
James Smartdb2378e2008-02-08 18:49:51 -05002367static void
2368lpfc_disable_msix(struct lpfc_hba *phba)
2369{
James Smart93996272008-08-24 21:50:30 -04002370 int i;
2371
2372 /* Free up MSI-X multi-message vectors */
2373 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2374 free_irq(phba->msix_entries[i].vector, phba);
2375 /* Disable MSI-X */
James Smartdb2378e2008-02-08 18:49:51 -05002376 pci_disable_msix(phba->pcidev);
2377}
2378
James Smarte59058c2008-08-24 21:49:00 -04002379/**
James Smart5b75da22008-12-04 22:39:35 -05002380 * lpfc_enable_msi: Enable MSI interrupt mode.
2381 * @phba: pointer to lpfc hba data structure.
2382 *
2383 * This routine is invoked to enable the MSI interrupt mode. The kernel
2384 * function pci_enable_msi() is called to enable the MSI vector. The
2385 * device driver is responsible for calling the request_irq() to register
2386 * MSI vector with a interrupt the handler, which is done in this function.
2387 *
2388 * Return codes
2389 * 0 - sucessful
2390 * other values - error
2391 */
2392static int
2393lpfc_enable_msi(struct lpfc_hba *phba)
2394{
2395 int rc;
2396
2397 rc = pci_enable_msi(phba->pcidev);
2398 if (!rc)
2399 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2400 "0462 PCI enable MSI mode success.\n");
2401 else {
2402 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2403 "0471 PCI enable MSI mode failed (%d)\n", rc);
2404 return rc;
2405 }
2406
2407 rc = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2408 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2409 if (rc) {
2410 pci_disable_msi(phba->pcidev);
2411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2412 "0478 MSI request_irq failed (%d)\n", rc);
2413 }
2414 return rc;
2415}
2416
2417/**
2418 * lpfc_disable_msi: Disable MSI interrupt mode.
2419 * @phba: pointer to lpfc hba data structure.
2420 *
2421 * This routine is invoked to disable the MSI interrupt mode. The driver
2422 * calls free_irq() on MSI vector it has done request_irq() on before
2423 * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and
2424 * a device will be left with MSI enabled and leaks its vector.
2425 */
2426
2427static void
2428lpfc_disable_msi(struct lpfc_hba *phba)
2429{
2430 free_irq(phba->pcidev->irq, phba);
2431 pci_disable_msi(phba->pcidev);
2432 return;
2433}
2434
2435/**
2436 * lpfc_log_intr_mode: Log the active interrupt mode
2437 * @phba: pointer to lpfc hba data structure.
2438 * @intr_mode: active interrupt mode adopted.
2439 *
2440 * This routine it invoked to log the currently used active interrupt mode
2441 * to the device.
2442 */
2443static void
2444lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
2445{
2446 switch (intr_mode) {
2447 case 0:
2448 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2449 "0470 Enable INTx interrupt mode.\n");
2450 break;
2451 case 1:
2452 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2453 "0481 Enabled MSI interrupt mode.\n");
2454 break;
2455 case 2:
2456 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2457 "0480 Enabled MSI-X interrupt mode.\n");
2458 break;
2459 default:
2460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2461 "0482 Illegal interrupt mode.\n");
2462 break;
2463 }
2464 return;
2465}
2466
2467static void
2468lpfc_stop_port(struct lpfc_hba *phba)
2469{
2470 /* Clear all interrupt enable conditions */
2471 writel(0, phba->HCregaddr);
2472 readl(phba->HCregaddr); /* flush */
2473 /* Clear all pending interrupts */
2474 writel(0xffffffff, phba->HAregaddr);
2475 readl(phba->HAregaddr); /* flush */
2476
2477 /* Reset some HBA SLI setup states */
2478 lpfc_stop_phba_timers(phba);
2479 phba->pport->work_port_events = 0;
2480
2481 return;
2482}
2483
2484/**
2485 * lpfc_enable_intr: Enable device interrupt.
2486 * @phba: pointer to lpfc hba data structure.
2487 *
2488 * This routine is invoked to enable device interrupt and associate driver's
2489 * interrupt handler(s) to interrupt vector(s). Depends on the interrupt
2490 * mode configured to the driver, the driver will try to fallback from the
2491 * configured interrupt mode to an interrupt mode which is supported by the
2492 * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ.
2493 *
2494 * Return codes
2495 * 0 - sucessful
2496 * other values - error
2497 **/
2498static uint32_t
2499lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
2500{
2501 uint32_t intr_mode = LPFC_INTR_ERROR;
2502 int retval;
2503
2504 if (cfg_mode == 2) {
2505 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
2506 retval = lpfc_sli_config_port(phba, 3);
2507 if (!retval) {
2508 /* Now, try to enable MSI-X interrupt mode */
2509 retval = lpfc_enable_msix(phba);
2510 if (!retval) {
2511 /* Indicate initialization to MSI-X mode */
2512 phba->intr_type = MSIX;
2513 intr_mode = 2;
2514 }
2515 }
2516 }
2517
2518 /* Fallback to MSI if MSI-X initialization failed */
2519 if (cfg_mode >= 1 && phba->intr_type == NONE) {
2520 retval = lpfc_enable_msi(phba);
2521 if (!retval) {
2522 /* Indicate initialization to MSI mode */
2523 phba->intr_type = MSI;
2524 intr_mode = 1;
2525 }
2526 }
2527
2528 /* Fallback to INTx if both MSI-X/MSI initalization failed */
2529 if (phba->intr_type == NONE) {
2530 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2531 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2532 if (!retval) {
2533 /* Indicate initialization to INTx mode */
2534 phba->intr_type = INTx;
2535 intr_mode = 0;
2536 }
2537 }
2538 return intr_mode;
2539}
2540
2541/**
2542 * lpfc_disable_intr: Disable device interrupt.
2543 * @phba: pointer to lpfc hba data structure.
2544 *
2545 * This routine is invoked to disable device interrupt and disassociate the
2546 * driver's interrupt handler(s) from interrupt vector(s). Depending on the
2547 * interrupt mode, the driver will release the interrupt vector(s) for the
2548 * message signaled interrupt.
2549 **/
2550static void
2551lpfc_disable_intr(struct lpfc_hba *phba)
2552{
2553 /* Disable the currently initialized interrupt mode */
2554 if (phba->intr_type == MSIX)
2555 lpfc_disable_msix(phba);
2556 else if (phba->intr_type == MSI)
2557 lpfc_disable_msi(phba);
2558 else if (phba->intr_type == INTx)
2559 free_irq(phba->pcidev->irq, phba);
2560
2561 /* Reset interrupt management states */
2562 phba->intr_type = NONE;
2563 phba->sli.slistat.sli_intr = 0;
2564
2565 return;
2566}
2567
2568/**
James Smarte59058c2008-08-24 21:49:00 -04002569 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2570 * @pdev: pointer to PCI device
2571 * @pid: pointer to PCI device identifier
2572 *
2573 * This routine is to be registered to the kernel's PCI subsystem. When an
2574 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2575 * PCI device-specific information of the device and driver to see if the
2576 * driver state that it can support this kind of device. If the match is
2577 * successful, the driver core invokes this routine. If this routine
2578 * determines it can claim the HBA, it does all the initialization that it
2579 * needs to do to handle the HBA properly.
2580 *
2581 * Return code
2582 * 0 - driver can claim the device
2583 * negative value - driver can not claim the device
2584 **/
dea31012005-04-17 16:05:31 -05002585static int __devinit
2586lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2587{
James Smart2e0fef82007-06-17 19:56:36 -05002588 struct lpfc_vport *vport = NULL;
2589 struct lpfc_hba *phba;
2590 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002591 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002592 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04002593 void *ptr;
dea31012005-04-17 16:05:31 -05002594 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04002595 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04002596 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05002597 uint16_t iotag;
James Smart5b75da22008-12-04 22:39:35 -05002598 uint32_t cfg_mode, intr_mode;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002599 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
James Smartea2151b2008-09-07 11:52:10 -04002600 struct lpfc_adapter_event_header adapter_event;
dea31012005-04-17 16:05:31 -05002601
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01002602 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05002603 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002604 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05002605 goto out_disable_device;
2606
James Smart2e0fef82007-06-17 19:56:36 -05002607 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2608 if (!phba)
dea31012005-04-17 16:05:31 -05002609 goto out_release_regions;
2610
James Smartea2151b2008-09-07 11:52:10 -04002611 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002612 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002613
James Smarte47c9092008-02-08 18:49:26 -05002614 /* Initialize ndlp management spinlock */
2615 spin_lock_init(&phba->ndlp_lock);
2616
dea31012005-04-17 16:05:31 -05002617 phba->pcidev = pdev;
2618
2619 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05002620 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05002621 goto out_free_phba;
dea31012005-04-17 16:05:31 -05002622
James Smart2e0fef82007-06-17 19:56:36 -05002623 INIT_LIST_HEAD(&phba->port_list);
James Smart84774a42008-08-24 21:50:06 -04002624 init_waitqueue_head(&phba->wait_4_mlo_m_q);
James Smart2e0fef82007-06-17 19:56:36 -05002625 /*
2626 * Get all the module params for configuring this host and then
2627 * establish the host.
2628 */
2629 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002630 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002631
2632 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05002633 init_timer(&phba->hb_tmofunc);
2634 phba->hb_tmofunc.function = lpfc_hb_timeout;
2635 phba->hb_tmofunc.data = (unsigned long)phba;
2636
dea31012005-04-17 16:05:31 -05002637 psli = &phba->sli;
2638 init_timer(&psli->mbox_tmo);
2639 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002640 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002641 init_timer(&phba->fcp_poll_timer);
2642 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002643 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002644 init_timer(&phba->fabric_block_timer);
2645 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2646 phba->fabric_block_timer.data = (unsigned long) phba;
James Smart93996272008-08-24 21:50:30 -04002647 init_timer(&phba->eratt_poll);
2648 phba->eratt_poll.function = lpfc_poll_eratt;
2649 phba->eratt_poll.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002650
dea31012005-04-17 16:05:31 -05002651 pci_set_master(pdev);
James Smart97207482008-12-04 22:39:19 -05002652 pci_save_state(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002653 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002654
2655 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2656 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2657 goto out_idr_remove;
2658
2659 /*
2660 * Get the bus address of Bar0 and Bar2 and the number of bytes
2661 * required by each mapping.
2662 */
2663 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2664 bar0map_len = pci_resource_len(phba->pcidev, 0);
2665
2666 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2667 bar2map_len = pci_resource_len(phba->pcidev, 2);
2668
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002669 /* Map HBA SLIM to a kernel virtual address. */
James Smart93996272008-08-24 21:50:30 -04002670 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002671 if (!phba->slim_memmap_p) {
2672 error = -ENODEV;
2673 dev_printk(KERN_ERR, &pdev->dev,
2674 "ioremap failed for SLIM memory.\n");
2675 goto out_idr_remove;
2676 }
2677
2678 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002679 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002680 if (!phba->ctrl_regs_memmap_p) {
2681 error = -ENODEV;
2682 dev_printk(KERN_ERR, &pdev->dev,
2683 "ioremap failed for HBA control registers.\n");
2684 goto out_iounmap_slim;
2685 }
dea31012005-04-17 16:05:31 -05002686
2687 /* Allocate memory for SLI-2 structures */
James Smart34b02dc2008-08-24 21:49:55 -04002688 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2689 SLI2_SLIM_SIZE,
2690 &phba->slim2p.phys,
2691 GFP_KERNEL);
2692 if (!phba->slim2p.virt)
dea31012005-04-17 16:05:31 -05002693 goto out_iounmap;
2694
James Smart34b02dc2008-08-24 21:49:55 -04002695 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
James Smartd7c255b2008-08-24 21:50:00 -04002696 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
2697 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
2698 phba->IOCBs = (phba->slim2p.virt +
2699 offsetof(struct lpfc_sli2_slim, IOCBs));
dea31012005-04-17 16:05:31 -05002700
James Smarted957682007-06-17 19:56:37 -05002701 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2702 lpfc_sli_hbq_size(),
2703 &phba->hbqslimp.phys,
2704 GFP_KERNEL);
2705 if (!phba->hbqslimp.virt)
2706 goto out_free_slim;
2707
James Smart51ef4c22007-08-02 11:10:31 -04002708 hbq_count = lpfc_sli_hbq_count();
2709 ptr = phba->hbqslimp.virt;
2710 for (i = 0; i < hbq_count; ++i) {
2711 phba->hbqs[i].hbq_virt = ptr;
2712 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2713 ptr += (lpfc_hbq_defs[i]->entry_count *
2714 sizeof(struct lpfc_hbq_entry));
2715 }
2716 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2717 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2718
James Smarted957682007-06-17 19:56:37 -05002719 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2720
James Smart3163f722008-02-08 18:50:25 -05002721 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2722
dea31012005-04-17 16:05:31 -05002723 /* Initialize the SLI Layer to run with lpfc HBAs. */
2724 lpfc_sli_setup(phba);
2725 lpfc_sli_queue_setup(phba);
2726
James Smart98c9ea52007-10-27 13:37:33 -04002727 retval = lpfc_mem_alloc(phba);
2728 if (retval) {
2729 error = retval;
James Smarted957682007-06-17 19:56:37 -05002730 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002731 }
dea31012005-04-17 16:05:31 -05002732
2733 /* Initialize and populate the iocb list per host. */
2734 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2735 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002736 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002737 if (iocbq_entry == NULL) {
2738 printk(KERN_ERR "%s: only allocated %d iocbs of "
2739 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002740 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002741 error = -ENOMEM;
2742 goto out_free_iocbq;
2743 }
2744
James Bottomley604a3e32005-10-29 10:28:33 -05002745 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2746 if (iotag == 0) {
2747 kfree (iocbq_entry);
2748 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2749 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002750 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002751 error = -ENOMEM;
2752 goto out_free_iocbq;
2753 }
James Smart2e0fef82007-06-17 19:56:36 -05002754
2755 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002756 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2757 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002758 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002759 }
2760
2761 /* Initialize HBA structure */
2762 phba->fc_edtov = FF_DEF_EDTOV;
2763 phba->fc_ratov = FF_DEF_RATOV;
2764 phba->fc_altov = FF_DEF_ALTOV;
2765 phba->fc_arbtov = FF_DEF_ARBTOV;
2766
2767 INIT_LIST_HEAD(&phba->work_list);
James Smart93996272008-08-24 21:50:30 -04002768 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
dea31012005-04-17 16:05:31 -05002769 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2770
James Smart5e9d9b82008-06-14 22:52:53 -04002771 /* Initialize the wait queue head for the kernel thread */
2772 init_waitqueue_head(&phba->work_waitq);
2773
dea31012005-04-17 16:05:31 -05002774 /* Startup the kernel thread for this host adapter. */
2775 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2776 "lpfc_worker_%d", phba->brd_no);
2777 if (IS_ERR(phba->worker_thread)) {
2778 error = PTR_ERR(phba->worker_thread);
2779 goto out_free_iocbq;
2780 }
2781
dea31012005-04-17 16:05:31 -05002782 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002783 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002784 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2785
James Smart92d7f7b2007-06-17 19:56:38 -05002786 /* Initialize list of fabric iocbs */
2787 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2788
James Smart0ff10d42008-01-11 01:52:36 -05002789 /* Initialize list to save ELS buffers */
2790 INIT_LIST_HEAD(&phba->elsbuf);
2791
James Smart3de2a652007-08-02 11:09:59 -04002792 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002793 if (!vport)
2794 goto out_kthread_stop;
2795
2796 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002797 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002798 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002799
James Smart92d7f7b2007-06-17 19:56:38 -05002800 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05002801
James Smart93996272008-08-24 21:50:30 -04002802 phba->MBslimaddr = phba->slim_memmap_p;
2803 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2804 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2805 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2806 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2807
James Smart5b75da22008-12-04 22:39:35 -05002808 /* Configure sysfs attributes */
James Smart98c9ea52007-10-27 13:37:33 -04002809 if (lpfc_alloc_sysfs_attr(vport)) {
James Smart93996272008-08-24 21:50:30 -04002810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2811 "1476 Failed to allocate sysfs attr\n");
James Smart98c9ea52007-10-27 13:37:33 -04002812 error = -ENOMEM;
James Smart5b75da22008-12-04 22:39:35 -05002813 goto out_destroy_port;
James Smart98c9ea52007-10-27 13:37:33 -04002814 }
dea31012005-04-17 16:05:31 -05002815
James Smart5b75da22008-12-04 22:39:35 -05002816 cfg_mode = phba->cfg_use_msi;
2817 while (true) {
2818 /* Configure and enable interrupt */
2819 intr_mode = lpfc_enable_intr(phba, cfg_mode);
2820 if (intr_mode == LPFC_INTR_ERROR) {
2821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2822 "0426 Failed to enable interrupt.\n");
2823 goto out_free_sysfs_attr;
2824 }
2825 /* HBA SLI setup */
2826 if (lpfc_sli_hba_setup(phba)) {
2827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2828 "1477 Failed to set up hba\n");
2829 error = -ENODEV;
2830 goto out_remove_device;
2831 }
2832
2833 /* Wait 50ms for the interrupts of previous mailbox commands */
2834 msleep(50);
2835 /* Check active interrupts received */
2836 if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
2837 /* Log the current active interrupt mode */
2838 phba->intr_mode = intr_mode;
2839 lpfc_log_intr_mode(phba, intr_mode);
2840 break;
2841 } else {
2842 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2843 "0451 Configure interrupt mode (%d) "
2844 "failed active interrupt test.\n",
2845 intr_mode);
2846 if (intr_mode == 0) {
2847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2848 "0479 Failed to enable "
2849 "interrupt.\n");
2850 error = -ENODEV;
2851 goto out_remove_device;
2852 }
2853 /* Stop HBA SLI setups */
2854 lpfc_stop_port(phba);
2855 /* Disable the current interrupt mode */
2856 lpfc_disable_intr(phba);
2857 /* Try next level of interrupt mode */
2858 cfg_mode = --intr_mode;
2859 }
James Smart98c9ea52007-10-27 13:37:33 -04002860 }
James Smart858c9f62007-06-17 19:56:39 -05002861
2862 /*
2863 * hba setup may have changed the hba_queue_depth so we need to adjust
2864 * the value of can_queue.
2865 */
2866 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2867
2868 lpfc_host_attrib_init(shost);
2869
James Smart2e0fef82007-06-17 19:56:36 -05002870 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2871 spin_lock_irq(shost->host_lock);
2872 lpfc_poll_start_timer(phba);
2873 spin_unlock_irq(shost->host_lock);
2874 }
James Smart8f6d98d2006-08-01 07:34:00 -04002875
James Smart93996272008-08-24 21:50:30 -04002876 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2877 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04002878 /* Send board arrival event to upper layer */
2879 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
2880 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
2881 fc_host_post_vendor_event(shost, fc_get_event_number(),
2882 sizeof(adapter_event),
2883 (char *) &adapter_event,
James Smartddcc50f2008-12-04 22:38:46 -05002884 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04002885
dea31012005-04-17 16:05:31 -05002886 return 0;
2887
James Smart858c9f62007-06-17 19:56:39 -05002888out_remove_device:
James Smart858c9f62007-06-17 19:56:39 -05002889 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002890 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002891 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002892 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002893 phba->pport->work_port_events = 0;
James Smart5b75da22008-12-04 22:39:35 -05002894 lpfc_disable_intr(phba);
James Smart9f1e1b52008-12-04 22:39:40 -05002895 lpfc_sli_hba_down(phba);
2896 lpfc_sli_brdrestart(phba);
James Smart5b75da22008-12-04 22:39:35 -05002897out_free_sysfs_attr:
2898 lpfc_free_sysfs_attr(vport);
2899out_destroy_port:
James Smart2e0fef82007-06-17 19:56:36 -05002900 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002901out_kthread_stop:
2902 kthread_stop(phba->worker_thread);
2903out_free_iocbq:
2904 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2905 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002906 kfree(iocbq_entry);
2907 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002908 }
2909 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002910out_free_hbqslimp:
James Smart34b02dc2008-08-24 21:49:55 -04002911 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2912 phba->hbqslimp.virt, phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002913out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04002914 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2915 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05002916out_iounmap:
2917 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002918out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002919 iounmap(phba->slim_memmap_p);
2920out_idr_remove:
2921 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002922out_free_phba:
2923 kfree(phba);
dea31012005-04-17 16:05:31 -05002924out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002925 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002926out_disable_device:
2927 pci_disable_device(pdev);
2928out:
James Smartdefbcf12006-04-16 22:26:50 -04002929 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002930 if (shost)
2931 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002932 return error;
2933}
2934
James Smarte59058c2008-08-24 21:49:00 -04002935/**
2936 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2937 * @pdev: pointer to PCI device
2938 *
2939 * This routine is to be registered to the kernel's PCI subsystem. When an
James Smart3a55b532008-12-04 22:38:54 -05002940 * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup
James Smarte59058c2008-08-24 21:49:00 -04002941 * for the HBA device to be removed from the PCI subsystem properly.
2942 **/
dea31012005-04-17 16:05:31 -05002943static void __devexit
2944lpfc_pci_remove_one(struct pci_dev *pdev)
2945{
James Smart2e0fef82007-06-17 19:56:36 -05002946 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2947 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05002948 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05002949 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05002950 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002951 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2952
James Smart549e55c2007-08-02 11:09:51 -04002953 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002954 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002955 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002956
James Smart858c9f62007-06-17 19:56:39 -05002957 lpfc_free_sysfs_attr(vport);
2958
James Smart09372822008-01-11 01:52:54 -05002959 kthread_stop(phba->worker_thread);
2960
James Smarteada2722008-12-04 22:39:13 -05002961 /* Release all the vports against this physical port */
2962 vports = lpfc_create_vport_work_array(phba);
2963 if (vports != NULL)
2964 for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++)
2965 fc_vport_terminate(vports[i]->fc_vport);
2966 lpfc_destroy_vport_work_array(phba, vports);
2967
2968 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05002969 fc_remove_host(shost);
2970 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002971 lpfc_cleanup(vport);
2972
James Smart2e0fef82007-06-17 19:56:36 -05002973 /*
2974 * Bring down the SLI Layer. This step disable all interrupts,
2975 * clears the rings, discards all mailbox commands, and resets
2976 * the HBA.
2977 */
2978 lpfc_sli_hba_down(phba);
2979 lpfc_sli_brdrestart(phba);
2980
James Smart92d7f7b2007-06-17 19:56:38 -05002981 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002982 spin_lock_irq(&phba->hbalock);
2983 list_del_init(&vport->listentry);
2984 spin_unlock_irq(&phba->hbalock);
2985
James Smart858c9f62007-06-17 19:56:39 -05002986 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002987
James Smart5b75da22008-12-04 22:39:35 -05002988 /* Disable interrupt */
2989 lpfc_disable_intr(phba);
dea31012005-04-17 16:05:31 -05002990
2991 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002992 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002993
2994 /*
2995 * Call scsi_free before mem_free since scsi bufs are released to their
2996 * corresponding pools here.
2997 */
2998 lpfc_scsi_free(phba);
2999 lpfc_mem_free(phba);
3000
James Smart34b02dc2008-08-24 21:49:55 -04003001 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
3002 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05003003
James Smart2e0fef82007-06-17 19:56:36 -05003004 /* Free resources associated with SLI2 interface */
3005 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04003006 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05003007
3008 /* unmap adapter SLIM and Control Registers */
3009 iounmap(phba->ctrl_regs_memmap_p);
3010 iounmap(phba->slim_memmap_p);
3011
3012 idr_remove(&lpfc_hba_index, phba->brd_no);
3013
3014 kfree(phba);
3015
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003016 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05003017 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05003018}
3019
Linas Vepstas8d63f372007-02-14 14:28:36 -06003020/**
James Smart3a55b532008-12-04 22:38:54 -05003021 * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management.
3022 * @pdev: pointer to PCI device
3023 * @msg: power management message
3024 *
3025 * This routine is to be registered to the kernel's PCI subsystem to support
3026 * system Power Management (PM). When PM invokes this method, it quiesces the
3027 * device by stopping the driver's worker thread for the device, turning off
3028 * device's interrupt and DMA, and bring the device offline. Note that as the
3029 * driver implements the minimum PM requirements to a power-aware driver's PM
3030 * support for suspend/resume -- all the possible PM messages (SUSPEND,
3031 * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND
3032 * and the driver will fully reinitialize its device during resume() method
3033 * call, the driver will set device to PCI_D3hot state in PCI config space
3034 * instead of setting it according to the @msg provided by the PM.
3035 *
3036 * Return code
3037 * 0 - driver suspended the device
3038 * Error otherwise
3039 **/
3040static int
3041lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
3042{
3043 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3044 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3045
3046 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3047 "0473 PCI device Power Management suspend.\n");
3048
3049 /* Bring down the device */
3050 lpfc_offline_prep(phba);
3051 lpfc_offline(phba);
3052 kthread_stop(phba->worker_thread);
3053
3054 /* Disable interrupt from device */
3055 lpfc_disable_intr(phba);
3056
3057 /* Save device state to PCI config space */
3058 pci_save_state(pdev);
3059 pci_set_power_state(pdev, PCI_D3hot);
3060
3061 return 0;
3062}
3063
3064/**
3065 * lpfc_pci_resume_one: lpfc PCI func to resume device for power management.
3066 * @pdev: pointer to PCI device
3067 *
3068 * This routine is to be registered to the kernel's PCI subsystem to support
3069 * system Power Management (PM). When PM invokes this method, it restores
3070 * the device's PCI config space state and fully reinitializes the device
3071 * and brings it online. Note that as the driver implements the minimum PM
3072 * requirements to a power-aware driver's PM for suspend/resume -- all
3073 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
3074 * method call will be treated as SUSPEND and the driver will fully
3075 * reinitialize its device during resume() method call, the device will be
3076 * set to PCI_D0 directly in PCI config space before restoring the state.
3077 *
3078 * Return code
3079 * 0 - driver suspended the device
3080 * Error otherwise
3081 **/
3082static int
3083lpfc_pci_resume_one(struct pci_dev *pdev)
3084{
3085 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3086 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05003087 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003088 int error;
3089
3090 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3091 "0452 PCI device Power Management resume.\n");
3092
3093 /* Restore device state from PCI config space */
3094 pci_set_power_state(pdev, PCI_D0);
3095 pci_restore_state(pdev);
3096 if (pdev->is_busmaster)
3097 pci_set_master(pdev);
3098
3099 /* Startup the kernel thread for this host adapter. */
3100 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3101 "lpfc_worker_%d", phba->brd_no);
3102 if (IS_ERR(phba->worker_thread)) {
3103 error = PTR_ERR(phba->worker_thread);
3104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3105 "0434 PM resume failed to start worker "
3106 "thread: error=x%x.\n", error);
3107 return error;
3108 }
3109
James Smart5b75da22008-12-04 22:39:35 -05003110 /* Configure and enable interrupt */
3111 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3112 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05003113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05003114 "0430 PM resume Failed to enable interrupt\n");
3115 return -EIO;
3116 } else
3117 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003118
3119 /* Restart HBA and bring it online */
3120 lpfc_sli_brdrestart(phba);
3121 lpfc_online(phba);
3122
James Smart5b75da22008-12-04 22:39:35 -05003123 /* Log the current active interrupt mode */
3124 lpfc_log_intr_mode(phba, phba->intr_mode);
3125
James Smart3a55b532008-12-04 22:38:54 -05003126 return 0;
3127}
3128
3129/**
James Smarte59058c2008-08-24 21:49:00 -04003130 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
3131 * @pdev: pointer to PCI device.
3132 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003133 *
James Smarte59058c2008-08-24 21:49:00 -04003134 * This routine is registered to the PCI subsystem for error handling. This
3135 * function is called by the PCI subsystem after a PCI bus error affecting
3136 * this device has been detected. When this function is invoked, it will
3137 * need to stop all the I/Os and interrupt(s) to the device. Once that is
3138 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
3139 * perform proper recovery as desired.
3140 *
3141 * Return codes
3142 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
3143 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
3144 **/
Linas Vepstas8d63f372007-02-14 14:28:36 -06003145static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
3146 pci_channel_state_t state)
3147{
James Smart51ef4c22007-08-02 11:10:31 -04003148 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3149 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003150 struct lpfc_sli *psli = &phba->sli;
3151 struct lpfc_sli_ring *pring;
3152
James Smarta8e497d2008-08-24 21:50:11 -04003153 if (state == pci_channel_io_perm_failure) {
3154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3155 "0472 PCI channel I/O permanent failure\n");
3156 /* Block all SCSI devices' I/Os on the host */
3157 lpfc_scsi_dev_block(phba);
3158 /* Clean up all driver's outstanding SCSI I/Os */
3159 lpfc_sli_flush_fcp_rings(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003160 return PCI_ERS_RESULT_DISCONNECT;
James Smarta8e497d2008-08-24 21:50:11 -04003161 }
Linas Vepstas5daa49e2007-03-08 16:19:11 -06003162
Linas Vepstas8d63f372007-02-14 14:28:36 -06003163 pci_disable_device(pdev);
3164 /*
3165 * There may be I/Os dropped by the firmware.
3166 * Error iocb (I/O) on txcmplq and let the SCSI layer
3167 * retry it after re-establishing link.
3168 */
3169 pring = &psli->ring[psli->fcp_ring];
3170 lpfc_sli_abort_iocb_ring(phba, pring);
3171
James Smart5b75da22008-12-04 22:39:35 -05003172 /* Disable interrupt */
3173 lpfc_disable_intr(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003174
Linas Vepstas8d63f372007-02-14 14:28:36 -06003175 /* Request a slot reset. */
3176 return PCI_ERS_RESULT_NEED_RESET;
3177}
3178
3179/**
James Smarte59058c2008-08-24 21:49:00 -04003180 * lpfc_io_slot_reset: Restart a PCI device from scratch.
3181 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003182 *
James Smarte59058c2008-08-24 21:49:00 -04003183 * This routine is registered to the PCI subsystem for error handling. This is
3184 * called after PCI bus has been reset to restart the PCI card from scratch,
3185 * as if from a cold-boot. During the PCI subsystem error recovery, after the
3186 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
3187 * proper error recovery and then call this routine before calling the .resume
3188 * method to recover the device. This function will initialize the HBA device,
3189 * enable the interrupt, but it will just put the HBA to offline state without
3190 * passing any I/O traffic.
3191 *
3192 * Return codes
3193 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
3194 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06003195 */
3196static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
3197{
James Smart51ef4c22007-08-02 11:10:31 -04003198 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3199 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003200 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05003201 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003202
3203 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003204 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06003205 printk(KERN_ERR "lpfc: Cannot re-enable "
3206 "PCI device after reset.\n");
3207 return PCI_ERS_RESULT_DISCONNECT;
3208 }
3209
James Smart97207482008-12-04 22:39:19 -05003210 pci_restore_state(pdev);
3211 if (pdev->is_busmaster)
3212 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003213
James Smart92d7f7b2007-06-17 19:56:38 -05003214 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003215 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05003216 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003217
James Smart5b75da22008-12-04 22:39:35 -05003218 /* Configure and enable interrupt */
3219 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3220 if (intr_mode == LPFC_INTR_ERROR) {
3221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3222 "0427 Cannot re-enable interrupt after "
3223 "slot reset.\n");
3224 return PCI_ERS_RESULT_DISCONNECT;
3225 } else
3226 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003227
3228 /* Take device offline; this will perform cleanup */
3229 lpfc_offline(phba);
3230 lpfc_sli_brdrestart(phba);
3231
James Smart5b75da22008-12-04 22:39:35 -05003232 /* Log the current active interrupt mode */
3233 lpfc_log_intr_mode(phba, phba->intr_mode);
3234
Linas Vepstas8d63f372007-02-14 14:28:36 -06003235 return PCI_ERS_RESULT_RECOVERED;
3236}
3237
3238/**
James Smarte59058c2008-08-24 21:49:00 -04003239 * lpfc_io_resume: Resume PCI I/O operation.
3240 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06003241 *
James Smarte59058c2008-08-24 21:49:00 -04003242 * This routine is registered to the PCI subsystem for error handling. It is
3243 * called when kernel error recovery tells the lpfc driver that it is ok to
3244 * resume normal PCI operation after PCI bus error recovery. After this call,
3245 * traffic can start to flow from this device again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003246 */
3247static void lpfc_io_resume(struct pci_dev *pdev)
3248{
James Smart51ef4c22007-08-02 11:10:31 -04003249 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3250 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003251
James Smart58da1ff2008-04-07 10:15:56 -04003252 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003253}
3254
dea31012005-04-17 16:05:31 -05003255static struct pci_device_id lpfc_id_table[] = {
3256 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
3257 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04003258 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
3259 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003260 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
3261 PCI_ANY_ID, PCI_ANY_ID, },
3262 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
3263 PCI_ANY_ID, PCI_ANY_ID, },
3264 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
3265 PCI_ANY_ID, PCI_ANY_ID, },
3266 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
3267 PCI_ANY_ID, PCI_ANY_ID, },
3268 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
3269 PCI_ANY_ID, PCI_ANY_ID, },
3270 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
3271 PCI_ANY_ID, PCI_ANY_ID, },
3272 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
3273 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003274 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
3275 PCI_ANY_ID, PCI_ANY_ID, },
3276 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
3277 PCI_ANY_ID, PCI_ANY_ID, },
3278 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
3279 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003280 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
3281 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003282 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
3283 PCI_ANY_ID, PCI_ANY_ID, },
3284 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
3285 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003286 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
3287 PCI_ANY_ID, PCI_ANY_ID, },
3288 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
3289 PCI_ANY_ID, PCI_ANY_ID, },
3290 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
3291 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003292 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
3293 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003294 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
3295 PCI_ANY_ID, PCI_ANY_ID, },
3296 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
3297 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003298 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
3299 PCI_ANY_ID, PCI_ANY_ID, },
3300 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
3301 PCI_ANY_ID, PCI_ANY_ID, },
3302 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
3303 PCI_ANY_ID, PCI_ANY_ID, },
3304 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
3305 PCI_ANY_ID, PCI_ANY_ID, },
3306 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
3307 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003308 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
3309 PCI_ANY_ID, PCI_ANY_ID, },
3310 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
3311 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04003312 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
3313 PCI_ANY_ID, PCI_ANY_ID, },
3314 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
3315 PCI_ANY_ID, PCI_ANY_ID, },
3316 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
3317 PCI_ANY_ID, PCI_ANY_ID, },
3318 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
3319 PCI_ANY_ID, PCI_ANY_ID, },
3320 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
3321 PCI_ANY_ID, PCI_ANY_ID, },
3322 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
3323 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003324 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
3325 PCI_ANY_ID, PCI_ANY_ID, },
3326 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
3327 PCI_ANY_ID, PCI_ANY_ID, },
3328 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
3329 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003330 { 0 }
3331};
3332
3333MODULE_DEVICE_TABLE(pci, lpfc_id_table);
3334
Linas Vepstas8d63f372007-02-14 14:28:36 -06003335static struct pci_error_handlers lpfc_err_handler = {
3336 .error_detected = lpfc_io_error_detected,
3337 .slot_reset = lpfc_io_slot_reset,
3338 .resume = lpfc_io_resume,
3339};
3340
dea31012005-04-17 16:05:31 -05003341static struct pci_driver lpfc_driver = {
3342 .name = LPFC_DRIVER_NAME,
3343 .id_table = lpfc_id_table,
3344 .probe = lpfc_pci_probe_one,
3345 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05003346 .suspend = lpfc_pci_suspend_one,
3347 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05003348 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05003349};
3350
James Smarte59058c2008-08-24 21:49:00 -04003351/**
3352 * lpfc_init: lpfc module initialization routine.
3353 *
3354 * This routine is to be invoked when the lpfc module is loaded into the
3355 * kernel. The special kernel macro module_init() is used to indicate the
3356 * role of this routine to the kernel as lpfc module entry point.
3357 *
3358 * Return codes
3359 * 0 - successful
3360 * -ENOMEM - FC attach transport failed
3361 * all others - failed
3362 */
dea31012005-04-17 16:05:31 -05003363static int __init
3364lpfc_init(void)
3365{
3366 int error = 0;
3367
3368 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003369 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05003370
James Smart7ee5d432007-10-27 13:37:17 -04003371 if (lpfc_enable_npiv) {
3372 lpfc_transport_functions.vport_create = lpfc_vport_create;
3373 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
3374 }
dea31012005-04-17 16:05:31 -05003375 lpfc_transport_template =
3376 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04003377 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05003378 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04003379 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04003380 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04003381 fc_attach_transport(&lpfc_vport_transport_functions);
3382 if (lpfc_vport_transport_template == NULL) {
3383 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003384 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04003385 }
James Smart7ee5d432007-10-27 13:37:17 -04003386 }
dea31012005-04-17 16:05:31 -05003387 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05003388 if (error) {
dea31012005-04-17 16:05:31 -05003389 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04003390 if (lpfc_enable_npiv)
3391 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05003392 }
dea31012005-04-17 16:05:31 -05003393
3394 return error;
3395}
3396
James Smarte59058c2008-08-24 21:49:00 -04003397/**
3398 * lpfc_exit: lpfc module removal routine.
3399 *
3400 * This routine is invoked when the lpfc module is removed from the kernel.
3401 * The special kernel macro module_exit() is used to indicate the role of
3402 * this routine to the kernel as lpfc module exit point.
3403 */
dea31012005-04-17 16:05:31 -05003404static void __exit
3405lpfc_exit(void)
3406{
3407 pci_unregister_driver(&lpfc_driver);
3408 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003409 if (lpfc_enable_npiv)
3410 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05003411}
3412
3413module_init(lpfc_init);
3414module_exit(lpfc_exit);
3415MODULE_LICENSE("GPL");
3416MODULE_DESCRIPTION(LPFC_MODULE_DESC);
3417MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
3418MODULE_VERSION("0:" LPFC_DRIVER_VERSION);