blob: 6c867311cef1d295a8f7e39b2b1b7c43107f4202 [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
James Smart81301a92008-12-04 22:39:46 -050048char *_dump_buf_data;
49unsigned long _dump_buf_data_order;
50char *_dump_buf_dif;
51unsigned long _dump_buf_dif_order;
52spinlock_t _dump_buf_lock;
53
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050054static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050055static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
56static int lpfc_post_rcv_buf(struct lpfc_hba *);
57
58static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050059static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050060static DEFINE_IDR(lpfc_hba_index);
61
James Smarte59058c2008-08-24 21:49:00 -040062/**
63 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
64 * @phba: pointer to lpfc hba data structure.
65 *
66 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
67 * mailbox command. It retrieves the revision information from the HBA and
68 * collects the Vital Product Data (VPD) about the HBA for preparing the
69 * configuration of the HBA.
70 *
71 * Return codes:
72 * 0 - success.
73 * -ERESTART - requests the SLI layer to reset the HBA and try again.
74 * Any other value - indicates an error.
75 **/
dea31012005-04-17 16:05:31 -050076int
James Smart2e0fef82007-06-17 19:56:36 -050077lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050078{
79 lpfc_vpd_t *vp = &phba->vpd;
80 int i = 0, rc;
81 LPFC_MBOXQ_t *pmb;
82 MAILBOX_t *mb;
83 char *lpfc_vpd_data = NULL;
84 uint16_t offset = 0;
85 static char licensed[56] =
86 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040087 static int init_key = 1;
dea31012005-04-17 16:05:31 -050088
89 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
90 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050091 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050092 return -ENOMEM;
93 }
94
95 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050096 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050097
98 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040099 if (init_key) {
100 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500101
James Smart65a29c12006-07-06 15:50:50 -0400102 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
103 *ptext = cpu_to_be32(*ptext);
104 init_key = 0;
105 }
dea31012005-04-17 16:05:31 -0500106
107 lpfc_read_nv(phba, pmb);
108 memset((char*)mb->un.varRDnvp.rsvd3, 0,
109 sizeof (mb->un.varRDnvp.rsvd3));
110 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
111 sizeof (licensed));
112
113 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
114
115 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400117 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500118 "error, mbxCmd x%x READ_NVPARM, "
119 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500120 mb->mbxCommand, mb->mbxStatus);
121 mempool_free(pmb, phba->mbox_mem_pool);
122 return -ERESTART;
123 }
124 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500125 sizeof(phba->wwnn));
126 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
127 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500128 }
129
James Smart92d7f7b2007-06-17 19:56:38 -0500130 phba->sli3_options = 0x0;
131
dea31012005-04-17 16:05:31 -0500132 /* Setup and issue mailbox READ REV command */
133 lpfc_read_rev(phba, pmb);
134 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
135 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400137 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500138 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500139 mb->mbxCommand, mb->mbxStatus);
140 mempool_free( pmb, phba->mbox_mem_pool);
141 return -ERESTART;
142 }
143
James Smart92d7f7b2007-06-17 19:56:38 -0500144
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500145 /*
146 * The value of rr must be 1 since the driver set the cv field to 1.
147 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500148 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500149 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500150 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400152 "0440 Adapter failed to init, READ_REV has "
153 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500154 mempool_free(pmb, phba->mbox_mem_pool);
155 return -ERESTART;
dea31012005-04-17 16:05:31 -0500156 }
157
James Smart495a7142008-06-14 22:52:59 -0400158 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
159 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500160 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400161 }
James Smarted957682007-06-17 19:56:37 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500164 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500165 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500166 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
167 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
168 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
169 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500170 vp->rev.biuRev = mb->un.varRdRev.biuRev;
171 vp->rev.smRev = mb->un.varRdRev.smRev;
172 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
173 vp->rev.endecRev = mb->un.varRdRev.endecRev;
174 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
175 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
176 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
177 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
178 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
179 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
180
James Smart92d7f7b2007-06-17 19:56:38 -0500181 /* If the sli feature level is less then 9, we must
182 * tear down all RPIs and VPIs on link down if NPIV
183 * is enabled.
184 */
185 if (vp->rev.feaLevelHigh < 9)
186 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
187
dea31012005-04-17 16:05:31 -0500188 if (lpfc_is_LC_HBA(phba->pcidev->device))
189 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
190 sizeof (phba->RandomData));
191
dea31012005-04-17 16:05:31 -0500192 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500193 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
194 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400195 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500196
197 do {
198 lpfc_dump_mem(phba, pmb, offset);
199 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
200
201 if (rc != MBX_SUCCESS) {
202 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400203 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500204 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500205 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500206 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500207 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500208 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
209 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400210 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
211 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500212 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500213 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500214 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
215 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500216
217 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500218out_free_mbox:
219 mempool_free(pmb, phba->mbox_mem_pool);
220 return 0;
221}
222
James Smarte59058c2008-08-24 21:49:00 -0400223/**
224 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
225 * @phba: pointer to lpfc hba data structure.
226 * @pmboxq: pointer to the driver internal queue element for mailbox command.
227 *
228 * This is the completion handler for driver's configuring asynchronous event
229 * mailbox command to the device. If the mailbox command returns successfully,
230 * it will set internal async event support flag to 1; otherwise, it will
231 * set internal async event support flag to 0.
232 **/
James Smart57127f12007-10-27 13:37:05 -0400233static void
234lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
235{
236 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
237 phba->temp_sensor_support = 1;
238 else
239 phba->temp_sensor_support = 0;
240 mempool_free(pmboxq, phba->mbox_mem_pool);
241 return;
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart97207482008-12-04 22:39:19 -0500245 * lpfc_dump_wakeup_param_cmpl: Completion handler for dump memory mailbox
246 * command used for getting wake up parameters.
247 * @phba: pointer to lpfc hba data structure.
248 * @pmboxq: pointer to the driver internal queue element for mailbox command.
249 *
250 * This is the completion handler for dump mailbox command for getting
251 * wake up parameters. When this command complete, the response contain
252 * Option rom version of the HBA. This function translate the version number
253 * into a human readable string and store it in OptionROMVersion.
254 **/
255static void
256lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
257{
258 struct prog_id *prg;
259 uint32_t prog_id_word;
260 char dist = ' ';
261 /* character array used for decoding dist type. */
262 char dist_char[] = "nabx";
263
James Smart9f1e1b52008-12-04 22:39:40 -0500264 if (pmboxq->mb.mbxStatus != MBX_SUCCESS) {
265 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500266 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500267 }
James Smart97207482008-12-04 22:39:19 -0500268
269 prg = (struct prog_id *) &prog_id_word;
270
271 /* word 7 contain option rom version */
272 prog_id_word = pmboxq->mb.un.varWords[7];
273
274 /* Decode the Option rom version word to a readable string */
275 if (prg->dist < 4)
276 dist = dist_char[prg->dist];
277
278 if ((prg->dist == 3) && (prg->num == 0))
279 sprintf(phba->OptionROMVersion, "%d.%d%d",
280 prg->ver, prg->rev, prg->lev);
281 else
282 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
283 prg->ver, prg->rev, prg->lev,
284 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500285 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500286 return;
287}
288
289/**
James Smarte59058c2008-08-24 21:49:00 -0400290 * lpfc_config_port_post: Perform lpfc initialization after config port.
291 * @phba: pointer to lpfc hba data structure.
292 *
293 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
294 * command call. It performs all internal resource and state setups on the
295 * port: post IOCB buffers, enable appropriate host interrupt attentions,
296 * ELS ring timers, etc.
297 *
298 * Return codes
299 * 0 - success.
300 * Any other value - error.
301 **/
dea31012005-04-17 16:05:31 -0500302int
James Smart2e0fef82007-06-17 19:56:36 -0500303lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500304{
James Smart2e0fef82007-06-17 19:56:36 -0500305 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500306 LPFC_MBOXQ_t *pmb;
307 MAILBOX_t *mb;
308 struct lpfc_dmabuf *mp;
309 struct lpfc_sli *psli = &phba->sli;
310 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500311 int i, j;
312 int rc;
dea31012005-04-17 16:05:31 -0500313
James Smart7af67052007-10-27 13:38:11 -0400314 spin_lock_irq(&phba->hbalock);
315 /*
316 * If the Config port completed correctly the HBA is not
317 * over heated any more.
318 */
319 if (phba->over_temp_state == HBA_OVER_TEMP)
320 phba->over_temp_state = HBA_NORMAL_TEMP;
321 spin_unlock_irq(&phba->hbalock);
322
dea31012005-04-17 16:05:31 -0500323 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
324 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500325 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500326 return -ENOMEM;
327 }
328 mb = &pmb->mb;
329
dea31012005-04-17 16:05:31 -0500330 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500331 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500332 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500333 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400335 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500336 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500337 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500338 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500339 mp = (struct lpfc_dmabuf *) pmb->context1;
340 mempool_free( pmb, phba->mbox_mem_pool);
341 lpfc_mbuf_free(phba, mp->virt, mp->phys);
342 kfree(mp);
343 return -EIO;
344 }
345
346 mp = (struct lpfc_dmabuf *) pmb->context1;
347
James Smart2e0fef82007-06-17 19:56:36 -0500348 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500349 lpfc_mbuf_free(phba, mp->virt, mp->phys);
350 kfree(mp);
351 pmb->context1 = NULL;
352
James Smarta12e07b2006-12-02 13:35:30 -0500353 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500354 u64_to_wwn(phba->cfg_soft_wwnn,
355 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400356 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500357 u64_to_wwn(phba->cfg_soft_wwpn,
358 vport->fc_sparam.portName.u.wwn);
359 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500360 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500361 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500362 sizeof (struct lpfc_name));
363 /* If no serial number in VPD data, use low 6 bytes of WWNN */
364 /* This should be consolidated into parse_vpd ? - mr */
365 if (phba->SerialNumber[0] == 0) {
366 uint8_t *outptr;
367
James Smart2e0fef82007-06-17 19:56:36 -0500368 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500369 for (i = 0; i < 12; i++) {
370 status = *outptr++;
371 j = ((status & 0xf0) >> 4);
372 if (j <= 9)
373 phba->SerialNumber[i] =
374 (char)((uint8_t) 0x30 + (uint8_t) j);
375 else
376 phba->SerialNumber[i] =
377 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
378 i++;
379 j = (status & 0xf);
380 if (j <= 9)
381 phba->SerialNumber[i] =
382 (char)((uint8_t) 0x30 + (uint8_t) j);
383 else
384 phba->SerialNumber[i] =
385 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
386 }
387 }
388
dea31012005-04-17 16:05:31 -0500389 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500390 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500391 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400393 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500394 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500395 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500396 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500397 mempool_free( pmb, phba->mbox_mem_pool);
398 return -EIO;
399 }
400
401 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
402 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
403 phba->cfg_hba_queue_depth =
404 mb->un.varRdConfig.max_xri + 1;
405
406 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500407
408 /* Get the default values for Model Name and Description */
409 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
410
411 if ((phba->cfg_link_speed > LINK_SPEED_10G)
412 || ((phba->cfg_link_speed == LINK_SPEED_1G)
413 && !(phba->lmt & LMT_1Gb))
414 || ((phba->cfg_link_speed == LINK_SPEED_2G)
415 && !(phba->lmt & LMT_2Gb))
416 || ((phba->cfg_link_speed == LINK_SPEED_4G)
417 && !(phba->lmt & LMT_4Gb))
418 || ((phba->cfg_link_speed == LINK_SPEED_8G)
419 && !(phba->lmt & LMT_8Gb))
420 || ((phba->cfg_link_speed == LINK_SPEED_10G)
421 && !(phba->lmt & LMT_10Gb))) {
422 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500423 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400424 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500425 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500426 phba->cfg_link_speed);
427 phba->cfg_link_speed = LINK_SPEED_AUTO;
428 }
429
James Smart2e0fef82007-06-17 19:56:36 -0500430 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500431
James Smart0b727fe2007-10-27 13:37:25 -0400432 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500433 if (psli->ring[psli->extra_ring].cmdringaddr)
434 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500435 if (psli->ring[psli->fcp_ring].cmdringaddr)
436 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
437 if (psli->ring[psli->next_ring].cmdringaddr)
438 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
439
440 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500441 if (phba->sli_rev != 3)
442 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500443
James Smart93996272008-08-24 21:50:30 -0400444 /*
445 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
446 */
447 if (phba->intr_type == MSIX) {
448 rc = lpfc_config_msi(phba, pmb);
449 if (rc) {
450 mempool_free(pmb, phba->mbox_mem_pool);
451 return -EIO;
452 }
453 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
454 if (rc != MBX_SUCCESS) {
455 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
456 "0352 Config MSI mailbox command "
457 "failed, mbxCmd x%x, mbxStatus x%x\n",
458 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
459 mempool_free(pmb, phba->mbox_mem_pool);
460 return -EIO;
461 }
462 }
463
464 /* Initialize ERATT handling flag */
465 phba->hba_flag &= ~HBA_ERATT_HANDLED;
466
dea31012005-04-17 16:05:31 -0500467 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500468 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500469 status = readl(phba->HCregaddr);
470 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
471 if (psli->num_rings > 0)
472 status |= HC_R0INT_ENA;
473 if (psli->num_rings > 1)
474 status |= HC_R1INT_ENA;
475 if (psli->num_rings > 2)
476 status |= HC_R2INT_ENA;
477 if (psli->num_rings > 3)
478 status |= HC_R3INT_ENA;
479
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500480 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
481 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400482 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500483
dea31012005-04-17 16:05:31 -0500484 writel(status, phba->HCregaddr);
485 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500486 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500487
James Smart93996272008-08-24 21:50:30 -0400488 /* Set up ring-0 (ELS) timer */
489 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500490 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400491 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500492 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
493 phba->hb_outstanding = 0;
494 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400495 /* Set up error attention (ERATT) polling timer */
496 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500497
498 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
499 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400500 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400501 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400502 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400504 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500505 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500506 mb->mbxCommand, mb->mbxStatus);
507
508 /* Clear all interrupt enable conditions */
509 writel(0, phba->HCregaddr);
510 readl(phba->HCregaddr); /* flush */
511 /* Clear all pending interrupts */
512 writel(0xffffffff, phba->HAregaddr);
513 readl(phba->HAregaddr); /* flush */
514
James Smart2e0fef82007-06-17 19:56:36 -0500515 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400516 if (rc != MBX_BUSY)
517 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500518 return -EIO;
519 }
520 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400521 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
522 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
523 pmb->mbox_cmpl = lpfc_config_async_cmpl;
524 pmb->vport = phba->pport;
525 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500526
James Smart57127f12007-10-27 13:37:05 -0400527 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
528 lpfc_printf_log(phba,
529 KERN_ERR,
530 LOG_INIT,
531 "0456 Adapter failed to issue "
532 "ASYNCEVT_ENABLE mbox status x%x \n.",
533 rc);
534 mempool_free(pmb, phba->mbox_mem_pool);
535 }
James Smart97207482008-12-04 22:39:19 -0500536
537 /* Get Option rom version */
538 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
539 lpfc_dump_wakeup_param(phba, pmb);
540 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
541 pmb->vport = phba->pport;
542 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
543
544 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
545 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
546 "to get Option ROM version status x%x\n.", rc);
547 mempool_free(pmb, phba->mbox_mem_pool);
548 }
549
James Smartd7c255b2008-08-24 21:50:00 -0400550 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400551}
552
James Smarte59058c2008-08-24 21:49:00 -0400553/**
554 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
555 * @phba: pointer to lpfc HBA data structure.
556 *
557 * This routine will do LPFC uninitialization before the HBA is reset when
558 * bringing down the SLI Layer.
559 *
560 * Return codes
561 * 0 - success.
562 * Any other value - error.
563 **/
dea31012005-04-17 16:05:31 -0500564int
James Smart2e0fef82007-06-17 19:56:36 -0500565lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500566{
James Smart1b32f6a2008-02-08 18:49:39 -0500567 struct lpfc_vport **vports;
568 int i;
dea31012005-04-17 16:05:31 -0500569 /* Disable interrupts */
570 writel(0, phba->HCregaddr);
571 readl(phba->HCregaddr); /* flush */
572
James Smart1b32f6a2008-02-08 18:49:39 -0500573 if (phba->pport->load_flag & FC_UNLOADING)
574 lpfc_cleanup_discovery_resources(phba->pport);
575 else {
576 vports = lpfc_create_vport_work_array(phba);
577 if (vports != NULL)
578 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
579 lpfc_cleanup_discovery_resources(vports[i]);
580 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500581 }
582 return 0;
dea31012005-04-17 16:05:31 -0500583}
584
James Smarte59058c2008-08-24 21:49:00 -0400585/**
586 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
587 * @phba: pointer to lpfc HBA data structure.
588 *
589 * This routine will do uninitialization after the HBA is reset when bring
590 * down the SLI Layer.
591 *
592 * Return codes
593 * 0 - sucess.
594 * Any other value - error.
595 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500596int
James Smart2e0fef82007-06-17 19:56:36 -0500597lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500598{
599 struct lpfc_sli *psli = &phba->sli;
600 struct lpfc_sli_ring *pring;
601 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500602 struct lpfc_iocbq *iocb;
603 IOCB_t *cmd = NULL;
604 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500605 int i;
606
James Smart92d7f7b2007-06-17 19:56:38 -0500607 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
608 lpfc_sli_hbqbuf_free_all(phba);
609 else {
610 /* Cleanup preposted buffers on the ELS ring */
611 pring = &psli->ring[LPFC_ELS_RING];
612 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
613 list_del(&mp->list);
614 pring->postbufq_cnt--;
615 lpfc_mbuf_free(phba, mp->virt, mp->phys);
616 kfree(mp);
617 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500618 }
619
James Smart09372822008-01-11 01:52:54 -0500620 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500621 for (i = 0; i < psli->num_rings; i++) {
622 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500623
624 /* At this point in time the HBA is either reset or DOA. Either
625 * way, nothing should be on txcmplq as it will NEVER complete.
626 */
627 list_splice_init(&pring->txcmplq, &completions);
628 pring->txcmplq_cnt = 0;
629 spin_unlock_irq(&phba->hbalock);
630
631 while (!list_empty(&completions)) {
632 iocb = list_get_first(&completions, struct lpfc_iocbq,
633 list);
634 cmd = &iocb->iocb;
635 list_del_init(&iocb->list);
636
637 if (!iocb->iocb_cmpl)
638 lpfc_sli_release_iocbq(phba, iocb);
639 else {
640 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
641 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
642 (iocb->iocb_cmpl) (phba, iocb, iocb);
643 }
644 }
645
Jamie Wellnitz41415862006-02-28 19:25:27 -0500646 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500647 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500648 }
James Smart09372822008-01-11 01:52:54 -0500649 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500650
651 return 0;
652}
653
James Smarte59058c2008-08-24 21:49:00 -0400654/**
655 * lpfc_hb_timeout: The HBA-timer timeout handler.
656 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
657 *
658 * This is the HBA-timer timeout handler registered to the lpfc driver. When
659 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
660 * work-port-events bitmap and the worker thread is notified. This timeout
661 * event will be used by the worker thread to invoke the actual timeout
662 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
663 * be performed in the timeout handler and the HBA timeout event bit shall
664 * be cleared by the worker thread after it has taken the event bitmap out.
665 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100666static void
James Smart858c9f62007-06-17 19:56:39 -0500667lpfc_hb_timeout(unsigned long ptr)
668{
669 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400670 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500671 unsigned long iflag;
672
673 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400674
675 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500676 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400677 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
678 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500679 phba->pport->work_port_events |= WORKER_HB_TMO;
680 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
681
James Smart93996272008-08-24 21:50:30 -0400682 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400683 if (!tmo_posted)
684 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500685 return;
686}
687
James Smarte59058c2008-08-24 21:49:00 -0400688/**
689 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
690 * @phba: pointer to lpfc hba data structure.
691 * @pmboxq: pointer to the driver internal queue element for mailbox command.
692 *
693 * This is the callback function to the lpfc heart-beat mailbox command.
694 * If configured, the lpfc driver issues the heart-beat mailbox command to
695 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
696 * heart-beat mailbox command is issued, the driver shall set up heart-beat
697 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
698 * heart-beat outstanding state. Once the mailbox command comes back and
699 * no error conditions detected, the heart-beat mailbox command timer is
700 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
701 * state is cleared for the next heart-beat. If the timer expired with the
702 * heart-beat outstanding state set, the driver will put the HBA offline.
703 **/
James Smart858c9f62007-06-17 19:56:39 -0500704static void
705lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
706{
707 unsigned long drvr_flag;
708
709 spin_lock_irqsave(&phba->hbalock, drvr_flag);
710 phba->hb_outstanding = 0;
711 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
712
James Smart93996272008-08-24 21:50:30 -0400713 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -0500714 mempool_free(pmboxq, phba->mbox_mem_pool);
715 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
716 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400717 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500718 mod_timer(&phba->hb_tmofunc,
719 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
720 return;
721}
722
James Smarte59058c2008-08-24 21:49:00 -0400723/**
724 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
725 * @phba: pointer to lpfc hba data structure.
726 *
727 * This is the actual HBA-timer timeout handler to be invoked by the worker
728 * thread whenever the HBA timer fired and HBA-timeout event posted. This
729 * handler performs any periodic operations needed for the device. If such
730 * periodic event has already been attended to either in the interrupt handler
731 * or by processing slow-ring or fast-ring events within the HBA-timer
732 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
733 * the timer for the next timeout period. If lpfc heart-beat mailbox command
734 * is configured and there is no heart-beat mailbox command outstanding, a
735 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
736 * has been a heart-beat mailbox command outstanding, the HBA shall be put
737 * to offline.
738 **/
James Smart858c9f62007-06-17 19:56:39 -0500739void
740lpfc_hb_timeout_handler(struct lpfc_hba *phba)
741{
742 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500743 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500744 int retval;
745 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500746 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500747
748 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400749 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500750 (phba->pport->fc_flag & FC_OFFLINE_MODE))
751 return;
752
753 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -0500754
755 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
756 jiffies)) {
757 spin_unlock_irq(&phba->pport->work_port_lock);
758 if (!phba->hb_outstanding)
759 mod_timer(&phba->hb_tmofunc,
760 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
761 else
762 mod_timer(&phba->hb_tmofunc,
763 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
764 return;
765 }
766 spin_unlock_irq(&phba->pport->work_port_lock);
767
James Smart0ff10d42008-01-11 01:52:36 -0500768 if (phba->elsbuf_cnt &&
769 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
770 spin_lock_irq(&phba->hbalock);
771 list_splice_init(&phba->elsbuf, &completions);
772 phba->elsbuf_cnt = 0;
773 phba->elsbuf_prev_cnt = 0;
774 spin_unlock_irq(&phba->hbalock);
775
776 while (!list_empty(&completions)) {
777 list_remove_head(&completions, buf_ptr,
778 struct lpfc_dmabuf, list);
779 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
780 kfree(buf_ptr);
781 }
782 }
783 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
784
James Smart858c9f62007-06-17 19:56:39 -0500785 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500786 if (phba->cfg_enable_hba_heartbeat) {
787 if (!phba->hb_outstanding) {
788 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
789 if (!pmboxq) {
790 mod_timer(&phba->hb_tmofunc,
791 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
792 return;
793 }
794
795 lpfc_heart_beat(phba, pmboxq);
796 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
797 pmboxq->vport = phba->pport;
798 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
799
800 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
801 mempool_free(pmboxq, phba->mbox_mem_pool);
802 mod_timer(&phba->hb_tmofunc,
803 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
804 return;
805 }
James Smart858c9f62007-06-17 19:56:39 -0500806 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500807 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
808 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500809 return;
James Smart13815c82008-01-11 01:52:48 -0500810 } else {
811 /*
812 * If heart beat timeout called with hb_outstanding set
813 * we need to take the HBA offline.
814 */
815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
816 "0459 Adapter heartbeat failure, "
817 "taking this port offline.\n");
818
819 spin_lock_irq(&phba->hbalock);
820 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
821 spin_unlock_irq(&phba->hbalock);
822
823 lpfc_offline_prep(phba);
824 lpfc_offline(phba);
825 lpfc_unblock_mgmt_io(phba);
826 phba->link_state = LPFC_HBA_ERROR;
827 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500828 }
James Smart858c9f62007-06-17 19:56:39 -0500829 }
830}
831
James Smarte59058c2008-08-24 21:49:00 -0400832/**
833 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
834 * @phba: pointer to lpfc hba data structure.
835 *
836 * This routine is called to bring the HBA offline when HBA hardware error
837 * other than Port Error 6 has been detected.
838 **/
James Smart09372822008-01-11 01:52:54 -0500839static void
840lpfc_offline_eratt(struct lpfc_hba *phba)
841{
842 struct lpfc_sli *psli = &phba->sli;
843
844 spin_lock_irq(&phba->hbalock);
845 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
846 spin_unlock_irq(&phba->hbalock);
847 lpfc_offline_prep(phba);
848
849 lpfc_offline(phba);
850 lpfc_reset_barrier(phba);
851 lpfc_sli_brdreset(phba);
852 lpfc_hba_down_post(phba);
853 lpfc_sli_brdready(phba, HS_MBRDY);
854 lpfc_unblock_mgmt_io(phba);
855 phba->link_state = LPFC_HBA_ERROR;
856 return;
857}
858
James Smarte59058c2008-08-24 21:49:00 -0400859/**
860 * lpfc_handle_eratt: The HBA hardware error handler.
861 * @phba: pointer to lpfc hba data structure.
862 *
863 * This routine is invoked to handle the following HBA hardware error
864 * conditions:
865 * 1 - HBA error attention interrupt
866 * 2 - DMA ring index out of range
867 * 3 - Mailbox command came back as unknown
868 **/
dea31012005-04-17 16:05:31 -0500869void
James Smart2e0fef82007-06-17 19:56:36 -0500870lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500871{
James Smart2e0fef82007-06-17 19:56:36 -0500872 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500873 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500874 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400875 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400876 unsigned long temperature;
877 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500878 struct Scsi_Host *shost;
James Smartea2151b2008-09-07 11:52:10 -0400879 struct lpfc_board_event_header board_event;
James Smart2e0fef82007-06-17 19:56:36 -0500880
Linas Vepstas8d63f372007-02-14 14:28:36 -0600881 /* If the pci channel is offline, ignore possible errors,
882 * since we cannot communicate with the pci card anyway. */
883 if (pci_channel_offline(phba->pcidev))
884 return;
James Smart13815c82008-01-11 01:52:48 -0500885 /* If resets are disabled then leave the HBA alone and return */
886 if (!phba->cfg_enable_hba_reset)
887 return;
dea31012005-04-17 16:05:31 -0500888
James Smartea2151b2008-09-07 11:52:10 -0400889 /* Send an internal error event to mgmt application */
890 board_event.event_type = FC_REG_BOARD_EVENT;
891 board_event.subcategory = LPFC_EVENT_PORTINTERR;
892 shost = lpfc_shost_from_vport(phba->pport);
893 fc_host_post_vendor_event(shost, fc_get_event_number(),
894 sizeof(board_event),
895 (char *) &board_event,
James Smartddcc50f2008-12-04 22:38:46 -0500896 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400897
James Smart97eab632008-04-07 10:16:05 -0400898 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500899 /* Re-establishing Link */
900 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400901 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500902 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400903 phba->work_hs,
dea31012005-04-17 16:05:31 -0500904 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400905
James Smart92d7f7b2007-06-17 19:56:38 -0500906 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500907 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500908 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500909
910 /*
911 * Firmware stops when it triggled erratt with HS_FFER6.
912 * That could cause the I/Os dropped by the firmware.
913 * Error iocb (I/O) on txcmplq and let the SCSI layer
914 * retry it after re-establishing link.
915 */
916 pring = &psli->ring[psli->fcp_ring];
917 lpfc_sli_abort_iocb_ring(phba, pring);
918
dea31012005-04-17 16:05:31 -0500919 /*
920 * There was a firmware error. Take the hba offline and then
921 * attempt to restart it.
922 */
James Smart46fa3112007-04-25 09:51:45 -0400923 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500924 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500925 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500926 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400927 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500928 return;
929 }
James Smart46fa3112007-04-25 09:51:45 -0400930 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400931 } else if (phba->work_hs & HS_CRIT_TEMP) {
932 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
933 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
934 temp_event_data.event_code = LPFC_CRIT_TEMP;
935 temp_event_data.data = (uint32_t)temperature;
936
937 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -0400938 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -0400939 "(%ld), taking this port offline "
940 "Data: x%x x%x x%x\n",
941 temperature, phba->work_hs,
942 phba->work_status[0], phba->work_status[1]);
943
944 shost = lpfc_shost_from_vport(phba->pport);
945 fc_host_post_vendor_event(shost, fc_get_event_number(),
946 sizeof(temp_event_data),
947 (char *) &temp_event_data,
948 SCSI_NL_VID_TYPE_PCI
949 | PCI_VENDOR_ID_EMULEX);
950
James Smart7af67052007-10-27 13:38:11 -0400951 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400952 phba->over_temp_state = HBA_OVER_TEMP;
953 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500954 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400955
dea31012005-04-17 16:05:31 -0500956 } else {
957 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -0400958 * failure is a value other than FFER6. Do not call the offline
959 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -0500960 */
961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400962 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500963 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400964 phba->work_hs,
dea31012005-04-17 16:05:31 -0500965 phba->work_status[0], phba->work_status[1]);
966
James Smartd2873e42006-08-18 17:46:43 -0400967 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500968 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500969 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400970 sizeof(event_data), (char *) &event_data,
971 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
972
James Smart09372822008-01-11 01:52:54 -0500973 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500974 }
James Smart93996272008-08-24 21:50:30 -0400975 return;
dea31012005-04-17 16:05:31 -0500976}
977
James Smarte59058c2008-08-24 21:49:00 -0400978/**
979 * lpfc_handle_latt: The HBA link event handler.
980 * @phba: pointer to lpfc hba data structure.
981 *
982 * This routine is invoked from the worker thread to handle a HBA host
983 * attention link event.
984 **/
dea31012005-04-17 16:05:31 -0500985void
James Smart2e0fef82007-06-17 19:56:36 -0500986lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500987{
James Smart2e0fef82007-06-17 19:56:36 -0500988 struct lpfc_vport *vport = phba->pport;
989 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500990 LPFC_MBOXQ_t *pmb;
991 volatile uint32_t control;
992 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500993 int rc = 0;
dea31012005-04-17 16:05:31 -0500994
995 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500996 if (!pmb) {
997 rc = 1;
dea31012005-04-17 16:05:31 -0500998 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500999 }
dea31012005-04-17 16:05:31 -05001000
1001 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001002 if (!mp) {
1003 rc = 2;
dea31012005-04-17 16:05:31 -05001004 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001005 }
dea31012005-04-17 16:05:31 -05001006
1007 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001008 if (!mp->virt) {
1009 rc = 3;
dea31012005-04-17 16:05:31 -05001010 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001011 }
dea31012005-04-17 16:05:31 -05001012
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001013 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001014 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001015
1016 psli->slistat.link_event++;
1017 lpfc_read_la(phba, pmb, mp);
1018 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -05001019 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001020 /* Block ELS IOCBs until we have processed this mbox command */
1021 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001022 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001023 if (rc == MBX_NOT_FINISHED) {
1024 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001025 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001026 }
dea31012005-04-17 16:05:31 -05001027
1028 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001029 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001030 writel(HA_LATT, phba->HAregaddr);
1031 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001032 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001033
1034 return;
1035
James Smart14691152006-12-02 13:34:28 -05001036lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001037 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001038 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001039lpfc_handle_latt_free_mp:
1040 kfree(mp);
1041lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001042 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001043lpfc_handle_latt_err_exit:
1044 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001045 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001046 psli->sli_flag |= LPFC_PROCESS_LA;
1047 control = readl(phba->HCregaddr);
1048 control |= HC_LAINT_ENA;
1049 writel(control, phba->HCregaddr);
1050 readl(phba->HCregaddr); /* flush */
1051
1052 /* Clear Link Attention in HA REG */
1053 writel(HA_LATT, phba->HAregaddr);
1054 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001055 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001056 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001057 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001058
James Smart09372822008-01-11 01:52:54 -05001059 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1060 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001061
1062 return;
1063}
1064
James Smarte59058c2008-08-24 21:49:00 -04001065/**
1066 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
1067 * @phba: pointer to lpfc hba data structure.
1068 * @vpd: pointer to the vital product data.
1069 * @len: length of the vital product data in bytes.
1070 *
1071 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1072 * an array of characters. In this routine, the ModelName, ProgramType, and
1073 * ModelDesc, etc. fields of the phba data structure will be populated.
1074 *
1075 * Return codes
1076 * 0 - pointer to the VPD passed in is NULL
1077 * 1 - success
1078 **/
dea31012005-04-17 16:05:31 -05001079static int
James Smart2e0fef82007-06-17 19:56:36 -05001080lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001081{
1082 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001083 int Length;
dea31012005-04-17 16:05:31 -05001084 int i, j;
1085 int finished = 0;
1086 int index = 0;
1087
1088 if (!vpd)
1089 return 0;
1090
1091 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001092 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001093 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001094 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1095 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001096 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001097 switch (vpd[index]) {
1098 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001099 case 0x91:
dea31012005-04-17 16:05:31 -05001100 index += 1;
1101 lenlo = vpd[index];
1102 index += 1;
1103 lenhi = vpd[index];
1104 index += 1;
1105 i = ((((unsigned short)lenhi) << 8) + lenlo);
1106 index += i;
1107 break;
1108 case 0x90:
1109 index += 1;
1110 lenlo = vpd[index];
1111 index += 1;
1112 lenhi = vpd[index];
1113 index += 1;
1114 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001115 if (Length > len - index)
1116 Length = len - index;
dea31012005-04-17 16:05:31 -05001117 while (Length > 0) {
1118 /* Look for Serial Number */
1119 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1120 index += 2;
1121 i = vpd[index];
1122 index += 1;
1123 j = 0;
1124 Length -= (3+i);
1125 while(i--) {
1126 phba->SerialNumber[j++] = vpd[index++];
1127 if (j == 31)
1128 break;
1129 }
1130 phba->SerialNumber[j] = 0;
1131 continue;
1132 }
1133 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1134 phba->vpd_flag |= VPD_MODEL_DESC;
1135 index += 2;
1136 i = vpd[index];
1137 index += 1;
1138 j = 0;
1139 Length -= (3+i);
1140 while(i--) {
1141 phba->ModelDesc[j++] = vpd[index++];
1142 if (j == 255)
1143 break;
1144 }
1145 phba->ModelDesc[j] = 0;
1146 continue;
1147 }
1148 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1149 phba->vpd_flag |= VPD_MODEL_NAME;
1150 index += 2;
1151 i = vpd[index];
1152 index += 1;
1153 j = 0;
1154 Length -= (3+i);
1155 while(i--) {
1156 phba->ModelName[j++] = vpd[index++];
1157 if (j == 79)
1158 break;
1159 }
1160 phba->ModelName[j] = 0;
1161 continue;
1162 }
1163 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1164 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1165 index += 2;
1166 i = vpd[index];
1167 index += 1;
1168 j = 0;
1169 Length -= (3+i);
1170 while(i--) {
1171 phba->ProgramType[j++] = vpd[index++];
1172 if (j == 255)
1173 break;
1174 }
1175 phba->ProgramType[j] = 0;
1176 continue;
1177 }
1178 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1179 phba->vpd_flag |= VPD_PORT;
1180 index += 2;
1181 i = vpd[index];
1182 index += 1;
1183 j = 0;
1184 Length -= (3+i);
1185 while(i--) {
1186 phba->Port[j++] = vpd[index++];
1187 if (j == 19)
1188 break;
1189 }
1190 phba->Port[j] = 0;
1191 continue;
1192 }
1193 else {
1194 index += 2;
1195 i = vpd[index];
1196 index += 1;
1197 index += i;
1198 Length -= (3 + i);
1199 }
1200 }
1201 finished = 0;
1202 break;
1203 case 0x78:
1204 finished = 1;
1205 break;
1206 default:
1207 index ++;
1208 break;
1209 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001210 }
dea31012005-04-17 16:05:31 -05001211
1212 return(1);
1213}
1214
James Smarte59058c2008-08-24 21:49:00 -04001215/**
1216 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1217 * @phba: pointer to lpfc hba data structure.
1218 * @mdp: pointer to the data structure to hold the derived model name.
1219 * @descp: pointer to the data structure to hold the derived description.
1220 *
1221 * This routine retrieves HBA's description based on its registered PCI device
1222 * ID. The @descp passed into this function points to an array of 256 chars. It
1223 * shall be returned with the model name, maximum speed, and the host bus type.
1224 * The @mdp passed into this function points to an array of 80 chars. When the
1225 * function returns, the @mdp will be filled with the model name.
1226 **/
dea31012005-04-17 16:05:31 -05001227static void
James Smart2e0fef82007-06-17 19:56:36 -05001228lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001229{
1230 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001231 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001232 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001233 int GE = 0;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001234 struct {
1235 char * name;
1236 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001237 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001238 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001239
1240 if (mdp && mdp[0] != '\0'
1241 && descp && descp[0] != '\0')
1242 return;
1243
1244 if (phba->lmt & LMT_10Gb)
1245 max_speed = 10;
1246 else if (phba->lmt & LMT_8Gb)
1247 max_speed = 8;
1248 else if (phba->lmt & LMT_4Gb)
1249 max_speed = 4;
1250 else if (phba->lmt & LMT_2Gb)
1251 max_speed = 2;
1252 else
1253 max_speed = 1;
dea31012005-04-17 16:05:31 -05001254
1255 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001256
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001257 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001258 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001259 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001260 break;
dea31012005-04-17 16:05:31 -05001261 case PCI_DEVICE_ID_SUPERFLY:
1262 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001263 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001264 else
James Smart18a3b592006-12-02 13:35:08 -05001265 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001266 break;
1267 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001268 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001269 break;
1270 case PCI_DEVICE_ID_CENTAUR:
1271 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001272 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001273 else
James Smart18a3b592006-12-02 13:35:08 -05001274 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001275 break;
1276 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001277 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001278 break;
1279 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001280 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001281 break;
1282 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001283 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001284 break;
1285 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001286 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001287 break;
1288 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001289 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001290 break;
1291 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001292 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001293 break;
1294 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001295 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001296 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001297 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001298 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001299 break;
1300 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001301 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001302 break;
1303 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001304 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001305 break;
1306 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001307 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001308 break;
1309 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001310 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001311 break;
dea31012005-04-17 16:05:31 -05001312 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001313 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001314 break;
1315 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001316 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001317 break;
1318 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001319 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001320 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001321 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001322 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001323 break;
1324 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001325 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001326 break;
dea31012005-04-17 16:05:31 -05001327 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001328 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001329 break;
1330 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001331 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001332 break;
1333 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001334 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001335 break;
1336 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001337 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001338 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001339 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001340 m = (typeof(m)){"LP11000-S", max_speed,
1341 "PCI-X2"};
1342 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001343 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001344 m = (typeof(m)){"LPe11000-S", max_speed,
1345 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001346 break;
James Smartb87eab32007-04-25 09:53:28 -04001347 case PCI_DEVICE_ID_SAT:
1348 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1349 break;
1350 case PCI_DEVICE_ID_SAT_MID:
1351 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1352 break;
1353 case PCI_DEVICE_ID_SAT_SMB:
1354 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1355 break;
1356 case PCI_DEVICE_ID_SAT_DCSP:
1357 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1358 break;
1359 case PCI_DEVICE_ID_SAT_SCSP:
1360 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1361 break;
1362 case PCI_DEVICE_ID_SAT_S:
1363 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1364 break;
James Smart84774a42008-08-24 21:50:06 -04001365 case PCI_DEVICE_ID_HORNET:
1366 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1367 GE = 1;
1368 break;
1369 case PCI_DEVICE_ID_PROTEUS_VF:
1370 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1371 break;
1372 case PCI_DEVICE_ID_PROTEUS_PF:
1373 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1374 break;
1375 case PCI_DEVICE_ID_PROTEUS_S:
1376 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1377 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001378 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001379 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001380 break;
dea31012005-04-17 16:05:31 -05001381 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001382
1383 if (mdp && mdp[0] == '\0')
1384 snprintf(mdp, 79,"%s", m.name);
1385 if (descp && descp[0] == '\0')
1386 snprintf(descp, 255,
James Smart84774a42008-08-24 21:50:06 -04001387 "Emulex %s %d%s %s %s",
1388 m.name, m.max_speed,
1389 (GE) ? "GE" : "Gb",
1390 m.bus,
1391 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
dea31012005-04-17 16:05:31 -05001392}
1393
James Smarte59058c2008-08-24 21:49:00 -04001394/**
1395 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1396 * @phba: pointer to lpfc hba data structure.
1397 * @pring: pointer to a IOCB ring.
1398 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1399 *
1400 * This routine posts a given number of IOCBs with the associated DMA buffer
1401 * descriptors specified by the cnt argument to the given IOCB ring.
1402 *
1403 * Return codes
1404 * The number of IOCBs NOT able to be posted to the IOCB ring.
1405 **/
dea31012005-04-17 16:05:31 -05001406int
James Smart495a7142008-06-14 22:52:59 -04001407lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001408{
1409 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001410 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001411 struct lpfc_dmabuf *mp1, *mp2;
1412
1413 cnt += pring->missbufcnt;
1414
1415 /* While there are buffers to post */
1416 while (cnt > 0) {
1417 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001418 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001419 if (iocb == NULL) {
1420 pring->missbufcnt = cnt;
1421 return cnt;
1422 }
dea31012005-04-17 16:05:31 -05001423 icmd = &iocb->iocb;
1424
1425 /* 2 buffers can be posted per command */
1426 /* Allocate buffer to post */
1427 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1428 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001429 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1430 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001431 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001432 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001433 pring->missbufcnt = cnt;
1434 return cnt;
1435 }
1436
1437 INIT_LIST_HEAD(&mp1->list);
1438 /* Allocate buffer to post */
1439 if (cnt > 1) {
1440 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1441 if (mp2)
1442 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1443 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001444 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001445 kfree(mp2);
dea31012005-04-17 16:05:31 -05001446 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1447 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001448 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001449 pring->missbufcnt = cnt;
1450 return cnt;
1451 }
1452
1453 INIT_LIST_HEAD(&mp2->list);
1454 } else {
1455 mp2 = NULL;
1456 }
1457
1458 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1459 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1460 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1461 icmd->ulpBdeCount = 1;
1462 cnt--;
1463 if (mp2) {
1464 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1465 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1466 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1467 cnt--;
1468 icmd->ulpBdeCount = 2;
1469 }
1470
1471 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1472 icmd->ulpLe = 1;
1473
dea31012005-04-17 16:05:31 -05001474 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1475 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1476 kfree(mp1);
1477 cnt++;
1478 if (mp2) {
1479 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1480 kfree(mp2);
1481 cnt++;
1482 }
James Bottomley604a3e32005-10-29 10:28:33 -05001483 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001484 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001485 return cnt;
1486 }
dea31012005-04-17 16:05:31 -05001487 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001488 if (mp2)
dea31012005-04-17 16:05:31 -05001489 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001490 }
1491 pring->missbufcnt = 0;
1492 return 0;
1493}
1494
James Smarte59058c2008-08-24 21:49:00 -04001495/**
1496 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1497 * @phba: pointer to lpfc hba data structure.
1498 *
1499 * This routine posts initial receive IOCB buffers to the ELS ring. The
1500 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1501 * set to 64 IOCBs.
1502 *
1503 * Return codes
1504 * 0 - success (currently always success)
1505 **/
dea31012005-04-17 16:05:31 -05001506static int
James Smart2e0fef82007-06-17 19:56:36 -05001507lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001508{
1509 struct lpfc_sli *psli = &phba->sli;
1510
1511 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001512 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001513 /* Ring 2 - FCP no buffers needed */
1514
1515 return 0;
1516}
1517
1518#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1519
James Smarte59058c2008-08-24 21:49:00 -04001520/**
1521 * lpfc_sha_init: Set up initial array of hash table entries.
1522 * @HashResultPointer: pointer to an array as hash table.
1523 *
1524 * This routine sets up the initial values to the array of hash table entries
1525 * for the LC HBAs.
1526 **/
dea31012005-04-17 16:05:31 -05001527static void
1528lpfc_sha_init(uint32_t * HashResultPointer)
1529{
1530 HashResultPointer[0] = 0x67452301;
1531 HashResultPointer[1] = 0xEFCDAB89;
1532 HashResultPointer[2] = 0x98BADCFE;
1533 HashResultPointer[3] = 0x10325476;
1534 HashResultPointer[4] = 0xC3D2E1F0;
1535}
1536
James Smarte59058c2008-08-24 21:49:00 -04001537/**
1538 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1539 * @HashResultPointer: pointer to an initial/result hash table.
1540 * @HashWorkingPointer: pointer to an working hash table.
1541 *
1542 * This routine iterates an initial hash table pointed by @HashResultPointer
1543 * with the values from the working hash table pointeed by @HashWorkingPointer.
1544 * The results are putting back to the initial hash table, returned through
1545 * the @HashResultPointer as the result hash table.
1546 **/
dea31012005-04-17 16:05:31 -05001547static void
1548lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1549{
1550 int t;
1551 uint32_t TEMP;
1552 uint32_t A, B, C, D, E;
1553 t = 16;
1554 do {
1555 HashWorkingPointer[t] =
1556 S(1,
1557 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1558 8] ^
1559 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1560 } while (++t <= 79);
1561 t = 0;
1562 A = HashResultPointer[0];
1563 B = HashResultPointer[1];
1564 C = HashResultPointer[2];
1565 D = HashResultPointer[3];
1566 E = HashResultPointer[4];
1567
1568 do {
1569 if (t < 20) {
1570 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1571 } else if (t < 40) {
1572 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1573 } else if (t < 60) {
1574 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1575 } else {
1576 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1577 }
1578 TEMP += S(5, A) + E + HashWorkingPointer[t];
1579 E = D;
1580 D = C;
1581 C = S(30, B);
1582 B = A;
1583 A = TEMP;
1584 } while (++t <= 79);
1585
1586 HashResultPointer[0] += A;
1587 HashResultPointer[1] += B;
1588 HashResultPointer[2] += C;
1589 HashResultPointer[3] += D;
1590 HashResultPointer[4] += E;
1591
1592}
1593
James Smarte59058c2008-08-24 21:49:00 -04001594/**
1595 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1596 * @RandomChallenge: pointer to the entry of host challenge random number array.
1597 * @HashWorking: pointer to the entry of the working hash array.
1598 *
1599 * This routine calculates the working hash array referred by @HashWorking
1600 * from the challenge random numbers associated with the host, referred by
1601 * @RandomChallenge. The result is put into the entry of the working hash
1602 * array and returned by reference through @HashWorking.
1603 **/
dea31012005-04-17 16:05:31 -05001604static void
1605lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1606{
1607 *HashWorking = (*RandomChallenge ^ *HashWorking);
1608}
1609
James Smarte59058c2008-08-24 21:49:00 -04001610/**
1611 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1612 * @phba: pointer to lpfc hba data structure.
1613 * @hbainit: pointer to an array of unsigned 32-bit integers.
1614 *
1615 * This routine performs the special handling for LC HBA initialization.
1616 **/
dea31012005-04-17 16:05:31 -05001617void
1618lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1619{
1620 int t;
1621 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001622 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001623
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001624 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001625 if (!HashWorking)
1626 return;
1627
dea31012005-04-17 16:05:31 -05001628 HashWorking[0] = HashWorking[78] = *pwwnn++;
1629 HashWorking[1] = HashWorking[79] = *pwwnn;
1630
1631 for (t = 0; t < 7; t++)
1632 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1633
1634 lpfc_sha_init(hbainit);
1635 lpfc_sha_iterate(hbainit, HashWorking);
1636 kfree(HashWorking);
1637}
1638
James Smarte59058c2008-08-24 21:49:00 -04001639/**
1640 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1641 * @vport: pointer to a virtual N_Port data structure.
1642 *
1643 * This routine performs the necessary cleanups before deleting the @vport.
1644 * It invokes the discovery state machine to perform necessary state
1645 * transitions and to release the ndlps associated with the @vport. Note,
1646 * the physical port is treated as @vport 0.
1647 **/
James Smart87af33f2007-10-27 13:37:43 -04001648void
James Smart2e0fef82007-06-17 19:56:36 -05001649lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001650{
James Smart87af33f2007-10-27 13:37:43 -04001651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001652 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001653 int i = 0;
dea31012005-04-17 16:05:31 -05001654
James Smart87af33f2007-10-27 13:37:43 -04001655 if (phba->link_state > LPFC_LINK_DOWN)
1656 lpfc_port_link_failure(vport);
1657
1658 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001659 if (!NLP_CHK_NODE_ACT(ndlp)) {
1660 ndlp = lpfc_enable_node(vport, ndlp,
1661 NLP_STE_UNUSED_NODE);
1662 if (!ndlp)
1663 continue;
1664 spin_lock_irq(&phba->ndlp_lock);
1665 NLP_SET_FREE_REQ(ndlp);
1666 spin_unlock_irq(&phba->ndlp_lock);
1667 /* Trigger the release of the ndlp memory */
1668 lpfc_nlp_put(ndlp);
1669 continue;
1670 }
1671 spin_lock_irq(&phba->ndlp_lock);
1672 if (NLP_CHK_FREE_REQ(ndlp)) {
1673 /* The ndlp should not be in memory free mode already */
1674 spin_unlock_irq(&phba->ndlp_lock);
1675 continue;
1676 } else
1677 /* Indicate request for freeing ndlp memory */
1678 NLP_SET_FREE_REQ(ndlp);
1679 spin_unlock_irq(&phba->ndlp_lock);
1680
James Smart58da1ff2008-04-07 10:15:56 -04001681 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1682 ndlp->nlp_DID == Fabric_DID) {
1683 /* Just free up ndlp with Fabric_DID for vports */
1684 lpfc_nlp_put(ndlp);
1685 continue;
1686 }
1687
James Smart87af33f2007-10-27 13:37:43 -04001688 if (ndlp->nlp_type & NLP_FABRIC)
1689 lpfc_disc_state_machine(vport, ndlp, NULL,
1690 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001691
James Smart87af33f2007-10-27 13:37:43 -04001692 lpfc_disc_state_machine(vport, ndlp, NULL,
1693 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001694
James Smart87af33f2007-10-27 13:37:43 -04001695 }
1696
James Smarta8adb832007-10-27 13:37:53 -04001697 /* At this point, ALL ndlp's should be gone
1698 * because of the previous NLP_EVT_DEVICE_RM.
1699 * Lets wait for this to happen, if needed.
1700 */
James Smart87af33f2007-10-27 13:37:43 -04001701 while (!list_empty(&vport->fc_nodes)) {
1702
James Smarta8adb832007-10-27 13:37:53 -04001703 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001704 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001705 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001706 list_for_each_entry_safe(ndlp, next_ndlp,
1707 &vport->fc_nodes, nlp_listp) {
1708 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1709 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001710 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001711 "usgmap:x%x refcnt:%d\n",
1712 ndlp->nlp_DID, (void *)ndlp,
1713 ndlp->nlp_usg_map,
1714 atomic_read(
1715 &ndlp->kref.refcount));
1716 }
James Smarta8adb832007-10-27 13:37:53 -04001717 break;
James Smart87af33f2007-10-27 13:37:43 -04001718 }
James Smarta8adb832007-10-27 13:37:53 -04001719
1720 /* Wait for any activity on ndlps to settle */
1721 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001722 }
dea31012005-04-17 16:05:31 -05001723 return;
1724}
1725
James Smarte59058c2008-08-24 21:49:00 -04001726/**
1727 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1728 * @vport: pointer to a virtual N_Port data structure.
1729 *
1730 * This routine stops all the timers associated with a @vport. This function
1731 * is invoked before disabling or deleting a @vport. Note that the physical
1732 * port is treated as @vport 0.
1733 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001734void
1735lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001736{
James Smart92d7f7b2007-06-17 19:56:38 -05001737 del_timer_sync(&vport->els_tmofunc);
1738 del_timer_sync(&vport->fc_fdmitmo);
1739 lpfc_can_disctmo(vport);
1740 return;
dea31012005-04-17 16:05:31 -05001741}
1742
James Smarte59058c2008-08-24 21:49:00 -04001743/**
1744 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1745 * @phba: pointer to lpfc hba data structure.
1746 *
1747 * This routine stops all the timers associated with a HBA. This function is
1748 * invoked before either putting a HBA offline or unloading the driver.
1749 **/
James Smart2e0fef82007-06-17 19:56:36 -05001750static void
James Smart92d7f7b2007-06-17 19:56:38 -05001751lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001752{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001753 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001754 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001755 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001756 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001757 phba->hb_outstanding = 0;
1758 del_timer_sync(&phba->hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001759 del_timer_sync(&phba->eratt_poll);
James Smart2e0fef82007-06-17 19:56:36 -05001760 return;
dea31012005-04-17 16:05:31 -05001761}
1762
James Smarte59058c2008-08-24 21:49:00 -04001763/**
1764 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1765 * @phba: pointer to lpfc hba data structure.
1766 *
1767 * This routine marks a HBA's management interface as blocked. Once the HBA's
1768 * management interface is marked as blocked, all the user space access to
1769 * the HBA, whether they are from sysfs interface or libdfc interface will
1770 * all be blocked. The HBA is set to block the management interface when the
1771 * driver prepares the HBA interface for online or offline.
1772 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001773static void
1774lpfc_block_mgmt_io(struct lpfc_hba * phba)
1775{
1776 unsigned long iflag;
1777
1778 spin_lock_irqsave(&phba->hbalock, iflag);
1779 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1780 spin_unlock_irqrestore(&phba->hbalock, iflag);
1781}
1782
James Smarte59058c2008-08-24 21:49:00 -04001783/**
1784 * lpfc_online: Initialize and bring a HBA online.
1785 * @phba: pointer to lpfc hba data structure.
1786 *
1787 * This routine initializes the HBA and brings a HBA online. During this
1788 * process, the management interface is blocked to prevent user space access
1789 * to the HBA interfering with the driver initialization.
1790 *
1791 * Return codes
1792 * 0 - successful
1793 * 1 - failed
1794 **/
dea31012005-04-17 16:05:31 -05001795int
James Smart2e0fef82007-06-17 19:56:36 -05001796lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001797{
Julia Lawall372bd282008-12-16 16:15:08 +01001798 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04001799 struct lpfc_vport **vports;
1800 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001801
dea31012005-04-17 16:05:31 -05001802 if (!phba)
1803 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01001804 vport = phba->pport;
dea31012005-04-17 16:05:31 -05001805
James Smart2e0fef82007-06-17 19:56:36 -05001806 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001807 return 0;
1808
James Smarted957682007-06-17 19:56:37 -05001809 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001810 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001811
James Smart46fa3112007-04-25 09:51:45 -04001812 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001813
James Smart46fa3112007-04-25 09:51:45 -04001814 if (!lpfc_sli_queue_setup(phba)) {
1815 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001816 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001817 }
1818
1819 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1820 lpfc_unblock_mgmt_io(phba);
1821 return 1;
1822 }
dea31012005-04-17 16:05:31 -05001823
James Smart549e55c2007-08-02 11:09:51 -04001824 vports = lpfc_create_vport_work_array(phba);
1825 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001826 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001827 struct Scsi_Host *shost;
1828 shost = lpfc_shost_from_vport(vports[i]);
1829 spin_lock_irq(shost->host_lock);
1830 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1831 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1832 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1833 spin_unlock_irq(shost->host_lock);
1834 }
James Smart09372822008-01-11 01:52:54 -05001835 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001836
James Smart46fa3112007-04-25 09:51:45 -04001837 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001838 return 0;
1839}
1840
James Smarte59058c2008-08-24 21:49:00 -04001841/**
1842 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1843 * @phba: pointer to lpfc hba data structure.
1844 *
1845 * This routine marks a HBA's management interface as not blocked. Once the
1846 * HBA's management interface is marked as not blocked, all the user space
1847 * access to the HBA, whether they are from sysfs interface or libdfc
1848 * interface will be allowed. The HBA is set to block the management interface
1849 * when the driver prepares the HBA interface for online or offline and then
1850 * set to unblock the management interface afterwards.
1851 **/
James Smart46fa3112007-04-25 09:51:45 -04001852void
James Smart46fa3112007-04-25 09:51:45 -04001853lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1854{
1855 unsigned long iflag;
1856
James Smart2e0fef82007-06-17 19:56:36 -05001857 spin_lock_irqsave(&phba->hbalock, iflag);
1858 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1859 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001860}
1861
James Smarte59058c2008-08-24 21:49:00 -04001862/**
1863 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1864 * @phba: pointer to lpfc hba data structure.
1865 *
1866 * This routine is invoked to prepare a HBA to be brought offline. It performs
1867 * unregistration login to all the nodes on all vports and flushes the mailbox
1868 * queue to make it ready to be brought offline.
1869 **/
James Smart46fa3112007-04-25 09:51:45 -04001870void
1871lpfc_offline_prep(struct lpfc_hba * phba)
1872{
James Smart2e0fef82007-06-17 19:56:36 -05001873 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001874 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001875 struct lpfc_vport **vports;
1876 int i;
dea31012005-04-17 16:05:31 -05001877
James Smart2e0fef82007-06-17 19:56:36 -05001878 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001879 return;
dea31012005-04-17 16:05:31 -05001880
James Smart46fa3112007-04-25 09:51:45 -04001881 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001882
1883 lpfc_linkdown(phba);
1884
James Smart87af33f2007-10-27 13:37:43 -04001885 /* Issue an unreg_login to all nodes on all vports */
1886 vports = lpfc_create_vport_work_array(phba);
1887 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001888 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001889 struct Scsi_Host *shost;
1890
James Smarta8adb832007-10-27 13:37:53 -04001891 if (vports[i]->load_flag & FC_UNLOADING)
1892 continue;
James Smart87af33f2007-10-27 13:37:43 -04001893 shost = lpfc_shost_from_vport(vports[i]);
1894 list_for_each_entry_safe(ndlp, next_ndlp,
1895 &vports[i]->fc_nodes,
1896 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001897 if (!NLP_CHK_NODE_ACT(ndlp))
1898 continue;
James Smart87af33f2007-10-27 13:37:43 -04001899 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1900 continue;
1901 if (ndlp->nlp_type & NLP_FABRIC) {
1902 lpfc_disc_state_machine(vports[i], ndlp,
1903 NULL, NLP_EVT_DEVICE_RECOVERY);
1904 lpfc_disc_state_machine(vports[i], ndlp,
1905 NULL, NLP_EVT_DEVICE_RM);
1906 }
1907 spin_lock_irq(shost->host_lock);
1908 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1909 spin_unlock_irq(shost->host_lock);
1910 lpfc_unreg_rpi(vports[i], ndlp);
1911 }
1912 }
1913 }
James Smart09372822008-01-11 01:52:54 -05001914 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001915
James Smart46fa3112007-04-25 09:51:45 -04001916 lpfc_sli_flush_mbox_queue(phba);
1917}
1918
James Smarte59058c2008-08-24 21:49:00 -04001919/**
1920 * lpfc_offline: Bring a HBA offline.
1921 * @phba: pointer to lpfc hba data structure.
1922 *
1923 * This routine actually brings a HBA offline. It stops all the timers
1924 * associated with the HBA, brings down the SLI layer, and eventually
1925 * marks the HBA as in offline state for the upper layer protocol.
1926 **/
James Smart46fa3112007-04-25 09:51:45 -04001927void
James Smart2e0fef82007-06-17 19:56:36 -05001928lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001929{
James Smart549e55c2007-08-02 11:09:51 -04001930 struct Scsi_Host *shost;
1931 struct lpfc_vport **vports;
1932 int i;
James Smart46fa3112007-04-25 09:51:45 -04001933
James Smart549e55c2007-08-02 11:09:51 -04001934 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001935 return;
James Smart688a8862006-07-06 15:49:56 -04001936
dea31012005-04-17 16:05:31 -05001937 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001938 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001939 vports = lpfc_create_vport_work_array(phba);
1940 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001941 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001942 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001943 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001944 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001945 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001946 /* Bring down the SLI Layer and cleanup. The HBA is offline
1947 now. */
1948 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001949 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001950 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001951 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001952 vports = lpfc_create_vport_work_array(phba);
1953 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001954 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001955 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001956 spin_lock_irq(shost->host_lock);
1957 vports[i]->work_port_events = 0;
1958 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1959 spin_unlock_irq(shost->host_lock);
1960 }
James Smart09372822008-01-11 01:52:54 -05001961 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001962}
1963
James Smarte59058c2008-08-24 21:49:00 -04001964/**
1965 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1966 * @phba: pointer to lpfc hba data structure.
1967 *
1968 * This routine is to free all the SCSI buffers and IOCBs from the driver
1969 * list back to kernel. It is called from lpfc_pci_remove_one to free
1970 * the internal resources before the device is removed from the system.
1971 *
1972 * Return codes
1973 * 0 - successful (for now, it always returns 0)
1974 **/
dea31012005-04-17 16:05:31 -05001975static int
James Smart2e0fef82007-06-17 19:56:36 -05001976lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001977{
1978 struct lpfc_scsi_buf *sb, *sb_next;
1979 struct lpfc_iocbq *io, *io_next;
1980
James Smart2e0fef82007-06-17 19:56:36 -05001981 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001982 /* Release all the lpfc_scsi_bufs maintained by this host. */
1983 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1984 list_del(&sb->list);
1985 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001986 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001987 kfree(sb);
1988 phba->total_scsi_bufs--;
1989 }
1990
1991 /* Release all the lpfc_iocbq entries maintained by this host. */
1992 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1993 list_del(&io->list);
1994 kfree(io);
1995 phba->total_iocbq_bufs--;
1996 }
1997
James Smart2e0fef82007-06-17 19:56:36 -05001998 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001999
2000 return 0;
2001}
2002
James Smarte59058c2008-08-24 21:49:00 -04002003/**
2004 * lpfc_create_port: Create an FC port.
2005 * @phba: pointer to lpfc hba data structure.
2006 * @instance: a unique integer ID to this FC port.
2007 * @dev: pointer to the device data structure.
2008 *
2009 * This routine creates a FC port for the upper layer protocol. The FC port
2010 * can be created on top of either a physical port or a virtual port provided
2011 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2012 * and associates the FC port created before adding the shost into the SCSI
2013 * layer.
2014 *
2015 * Return codes
2016 * @vport - pointer to the virtual N_Port data structure.
2017 * NULL - port create failed.
2018 **/
James Smart2e0fef82007-06-17 19:56:36 -05002019struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002020lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002021{
James Smart2e0fef82007-06-17 19:56:36 -05002022 struct lpfc_vport *vport;
2023 struct Scsi_Host *shost;
2024 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002025
James Smart3de2a652007-08-02 11:09:59 -04002026 if (dev != &phba->pcidev->dev)
2027 shost = scsi_host_alloc(&lpfc_vport_template,
2028 sizeof(struct lpfc_vport));
2029 else
2030 shost = scsi_host_alloc(&lpfc_template,
2031 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002032 if (!shost)
2033 goto out;
James Smart47a86172007-04-25 09:53:22 -04002034
James Smart2e0fef82007-06-17 19:56:36 -05002035 vport = (struct lpfc_vport *) shost->hostdata;
2036 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002037 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002038 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002039 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002040
James Smart3de2a652007-08-02 11:09:59 -04002041 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002042 shost->unique_id = instance;
2043 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002044 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002045 shost->this_id = -1;
2046 shost->max_cmd_len = 16;
James Smart81301a92008-12-04 22:39:46 -05002047
James Smart47a86172007-04-25 09:53:22 -04002048 /*
James Smart2e0fef82007-06-17 19:56:36 -05002049 * Set initial can_queue value since 0 is no longer supported and
2050 * scsi_add_host will fail. This will be adjusted later based on the
2051 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002052 */
James Smart2e0fef82007-06-17 19:56:36 -05002053 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002054 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002055 shost->transportt = lpfc_vport_transport_template;
2056 vport->port_type = LPFC_NPIV_PORT;
2057 } else {
2058 shost->transportt = lpfc_transport_template;
2059 vport->port_type = LPFC_PHYSICAL_PORT;
2060 }
James Smart47a86172007-04-25 09:53:22 -04002061
James Smart2e0fef82007-06-17 19:56:36 -05002062 /* Initialize all internally managed lists. */
2063 INIT_LIST_HEAD(&vport->fc_nodes);
2064 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002065
James Smart2e0fef82007-06-17 19:56:36 -05002066 init_timer(&vport->fc_disctmo);
2067 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002068 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002069
James Smart2e0fef82007-06-17 19:56:36 -05002070 init_timer(&vport->fc_fdmitmo);
2071 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002072 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002073
James Smart2e0fef82007-06-17 19:56:36 -05002074 init_timer(&vport->els_tmofunc);
2075 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002076 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002077
James Smart3de2a652007-08-02 11:09:59 -04002078 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05002079 if (error)
2080 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002081
James Smart549e55c2007-08-02 11:09:51 -04002082 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002083 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002084 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002085 return vport;
James Smart47a86172007-04-25 09:53:22 -04002086
James Smart2e0fef82007-06-17 19:56:36 -05002087out_put_shost:
2088 scsi_host_put(shost);
2089out:
2090 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002091}
2092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
2094 * destroy_port: Destroy an FC port.
2095 * @vport: pointer to an lpfc virtual N_Port data structure.
2096 *
2097 * This routine destroys a FC port from the upper layer protocol. All the
2098 * resources associated with the port are released.
2099 **/
James Smart2e0fef82007-06-17 19:56:36 -05002100void
2101destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002102{
James Smart92d7f7b2007-06-17 19:56:38 -05002103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2104 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002105
James Smart858c9f62007-06-17 19:56:39 -05002106 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002107 fc_remove_host(shost);
2108 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002109
James Smart92d7f7b2007-06-17 19:56:38 -05002110 spin_lock_irq(&phba->hbalock);
2111 list_del_init(&vport->listentry);
2112 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002113
James Smart92d7f7b2007-06-17 19:56:38 -05002114 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002115 return;
James Smart47a86172007-04-25 09:53:22 -04002116}
2117
James Smarte59058c2008-08-24 21:49:00 -04002118/**
2119 * lpfc_get_instance: Get a unique integer ID.
2120 *
2121 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2122 * uses the kernel idr facility to perform the task.
2123 *
2124 * Return codes:
2125 * instance - a unique integer ID allocated as the new instance.
2126 * -1 - lpfc get instance failed.
2127 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002128int
2129lpfc_get_instance(void)
2130{
2131 int instance = 0;
2132
2133 /* Assign an unused number */
2134 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2135 return -1;
2136 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2137 return -1;
2138 return instance;
2139}
2140
James Smarte59058c2008-08-24 21:49:00 -04002141/**
2142 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2143 * @shost: pointer to SCSI host data structure.
2144 * @time: elapsed time of the scan in jiffies.
2145 *
2146 * This routine is called by the SCSI layer with a SCSI host to determine
2147 * whether the scan host is finished.
2148 *
2149 * Note: there is no scan_start function as adapter initialization will have
2150 * asynchronously kicked off the link initialization.
2151 *
2152 * Return codes
2153 * 0 - SCSI host scan is not over yet.
2154 * 1 - SCSI host scan is over.
2155 **/
James Smart47a86172007-04-25 09:53:22 -04002156int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2157{
James Smart2e0fef82007-06-17 19:56:36 -05002158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2159 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002160 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002161
James Smart858c9f62007-06-17 19:56:39 -05002162 spin_lock_irq(shost->host_lock);
2163
James Smart51ef4c22007-08-02 11:10:31 -04002164 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002165 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002166 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002167 }
James Smart2e0fef82007-06-17 19:56:36 -05002168 if (time >= 30 * HZ) {
2169 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002170 "0461 Scanning longer than 30 "
2171 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002172 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002173 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002174 }
2175 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2176 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002177 "0465 Link down longer than 15 "
2178 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002179 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002180 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002181 }
2182
James Smart2e0fef82007-06-17 19:56:36 -05002183 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002184 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002185 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002186 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002187 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002188 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002189 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002190 goto finished;
2191
2192 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002193
2194finished:
James Smart858c9f62007-06-17 19:56:39 -05002195 spin_unlock_irq(shost->host_lock);
2196 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002197}
2198
James Smarte59058c2008-08-24 21:49:00 -04002199/**
2200 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2201 * @shost: pointer to SCSI host data structure.
2202 *
2203 * This routine initializes a given SCSI host attributes on a FC port. The
2204 * SCSI host can be either on top of a physical port or a virtual port.
2205 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002206void lpfc_host_attrib_init(struct Scsi_Host *shost)
2207{
2208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2209 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002210 /*
James Smart2e0fef82007-06-17 19:56:36 -05002211 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002212 */
2213
James Smart2e0fef82007-06-17 19:56:36 -05002214 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2215 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002216 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2217
2218 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002219 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002220 fc_host_supported_fc4s(shost)[2] = 1;
2221 fc_host_supported_fc4s(shost)[7] = 1;
2222
James Smart92d7f7b2007-06-17 19:56:38 -05002223 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2224 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002225
2226 fc_host_supported_speeds(shost) = 0;
2227 if (phba->lmt & LMT_10Gb)
2228 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002229 if (phba->lmt & LMT_8Gb)
2230 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002231 if (phba->lmt & LMT_4Gb)
2232 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2233 if (phba->lmt & LMT_2Gb)
2234 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2235 if (phba->lmt & LMT_1Gb)
2236 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2237
2238 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002239 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2240 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002241
2242 /* This value is also unchanging */
2243 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002244 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002245 fc_host_active_fc4s(shost)[2] = 1;
2246 fc_host_active_fc4s(shost)[7] = 1;
2247
James Smart92d7f7b2007-06-17 19:56:38 -05002248 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002249 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002250 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002251 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002252}
dea31012005-04-17 16:05:31 -05002253
James Smarte59058c2008-08-24 21:49:00 -04002254/**
2255 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2256 * @phba: pointer to lpfc hba data structure.
2257 *
2258 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2259 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2260 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2261 * on the current availability of PCI vector resources. The device driver is
2262 * responsible for calling the individual request_irq() to register each MSI-X
2263 * vector with a interrupt handler, which is done in this function. Note that
2264 * later when device is unloading, the driver should always call free_irq()
2265 * on all MSI-X vectors it has done request_irq() on before calling
2266 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2267 * will be left with MSI-X enabled and leaks its vectors.
2268 *
2269 * Return codes
2270 * 0 - sucessful
2271 * other values - error
2272 **/
James Smartdb2378e2008-02-08 18:49:51 -05002273static int
2274lpfc_enable_msix(struct lpfc_hba *phba)
2275{
James Smart93996272008-08-24 21:50:30 -04002276 int rc, i;
2277 LPFC_MBOXQ_t *pmb;
James Smartdb2378e2008-02-08 18:49:51 -05002278
James Smart93996272008-08-24 21:50:30 -04002279 /* Set up MSI-X multi-message vectors */
2280 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2281 phba->msix_entries[i].entry = i;
James Smartdb2378e2008-02-08 18:49:51 -05002282
James Smart93996272008-08-24 21:50:30 -04002283 /* Configure MSI-X capability structure */
2284 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
James Smartdb2378e2008-02-08 18:49:51 -05002285 ARRAY_SIZE(phba->msix_entries));
James Smart93996272008-08-24 21:50:30 -04002286 if (rc) {
James Smartdb2378e2008-02-08 18:49:51 -05002287 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05002288 "0420 PCI enable MSI-X failed (%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002289 goto msi_fail_out;
2290 } else
2291 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2292 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2293 "0477 MSI-X entry[%d]: vector=x%x "
2294 "message=%d\n", i,
2295 phba->msix_entries[i].vector,
2296 phba->msix_entries[i].entry);
2297 /*
2298 * Assign MSI-X vectors to interrupt handlers
2299 */
2300
2301 /* vector-0 is associated to slow-path handler */
2302 rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler,
2303 IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba);
2304 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002305 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002306 "0421 MSI-X slow-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002307 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002308 goto msi_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002309 }
2310
James Smart93996272008-08-24 21:50:30 -04002311 /* vector-1 is associated to fast-path handler */
2312 rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler,
2313 IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba);
2314
2315 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002316 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002317 "0429 MSI-X fast-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002318 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002319 goto irq_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002320 }
James Smart93996272008-08-24 21:50:30 -04002321
2322 /*
2323 * Configure HBA MSI-X attention conditions to messages
2324 */
2325 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2326
2327 if (!pmb) {
2328 rc = -ENOMEM;
2329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2330 "0474 Unable to allocate memory for issuing "
2331 "MBOX_CONFIG_MSI command\n");
2332 goto mem_fail_out;
2333 }
2334 rc = lpfc_config_msi(phba, pmb);
2335 if (rc)
2336 goto mbx_fail_out;
2337 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2338 if (rc != MBX_SUCCESS) {
James Smart5b75da22008-12-04 22:39:35 -05002339 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smart93996272008-08-24 21:50:30 -04002340 "0351 Config MSI mailbox command failed, "
2341 "mbxCmd x%x, mbxStatus x%x\n",
2342 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
2343 goto mbx_fail_out;
2344 }
2345
2346 /* Free memory allocated for mailbox command */
2347 mempool_free(pmb, phba->mbox_mem_pool);
2348 return rc;
2349
2350mbx_fail_out:
2351 /* Free memory allocated for mailbox command */
2352 mempool_free(pmb, phba->mbox_mem_pool);
2353
2354mem_fail_out:
2355 /* free the irq already requested */
2356 free_irq(phba->msix_entries[1].vector, phba);
2357
2358irq_fail_out:
2359 /* free the irq already requested */
2360 free_irq(phba->msix_entries[0].vector, phba);
2361
2362msi_fail_out:
2363 /* Unconfigure MSI-X capability structure */
2364 pci_disable_msix(phba->pcidev);
2365 return rc;
James Smartdb2378e2008-02-08 18:49:51 -05002366}
2367
James Smarte59058c2008-08-24 21:49:00 -04002368/**
2369 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2370 * @phba: pointer to lpfc hba data structure.
2371 *
2372 * This routine is invoked to release the MSI-X vectors and then disable the
2373 * MSI-X interrupt mode.
2374 **/
James Smartdb2378e2008-02-08 18:49:51 -05002375static void
2376lpfc_disable_msix(struct lpfc_hba *phba)
2377{
James Smart93996272008-08-24 21:50:30 -04002378 int i;
2379
2380 /* Free up MSI-X multi-message vectors */
2381 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2382 free_irq(phba->msix_entries[i].vector, phba);
2383 /* Disable MSI-X */
James Smartdb2378e2008-02-08 18:49:51 -05002384 pci_disable_msix(phba->pcidev);
2385}
2386
James Smarte59058c2008-08-24 21:49:00 -04002387/**
James Smart5b75da22008-12-04 22:39:35 -05002388 * lpfc_enable_msi: Enable MSI interrupt mode.
2389 * @phba: pointer to lpfc hba data structure.
2390 *
2391 * This routine is invoked to enable the MSI interrupt mode. The kernel
2392 * function pci_enable_msi() is called to enable the MSI vector. The
2393 * device driver is responsible for calling the request_irq() to register
2394 * MSI vector with a interrupt the handler, which is done in this function.
2395 *
2396 * Return codes
2397 * 0 - sucessful
2398 * other values - error
2399 */
2400static int
2401lpfc_enable_msi(struct lpfc_hba *phba)
2402{
2403 int rc;
2404
2405 rc = pci_enable_msi(phba->pcidev);
2406 if (!rc)
2407 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2408 "0462 PCI enable MSI mode success.\n");
2409 else {
2410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2411 "0471 PCI enable MSI mode failed (%d)\n", rc);
2412 return rc;
2413 }
2414
2415 rc = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2416 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2417 if (rc) {
2418 pci_disable_msi(phba->pcidev);
2419 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2420 "0478 MSI request_irq failed (%d)\n", rc);
2421 }
2422 return rc;
2423}
2424
2425/**
2426 * lpfc_disable_msi: Disable MSI interrupt mode.
2427 * @phba: pointer to lpfc hba data structure.
2428 *
2429 * This routine is invoked to disable the MSI interrupt mode. The driver
2430 * calls free_irq() on MSI vector it has done request_irq() on before
2431 * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and
2432 * a device will be left with MSI enabled and leaks its vector.
2433 */
2434
2435static void
2436lpfc_disable_msi(struct lpfc_hba *phba)
2437{
2438 free_irq(phba->pcidev->irq, phba);
2439 pci_disable_msi(phba->pcidev);
2440 return;
2441}
2442
2443/**
2444 * lpfc_log_intr_mode: Log the active interrupt mode
2445 * @phba: pointer to lpfc hba data structure.
2446 * @intr_mode: active interrupt mode adopted.
2447 *
2448 * This routine it invoked to log the currently used active interrupt mode
2449 * to the device.
2450 */
2451static void
2452lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
2453{
2454 switch (intr_mode) {
2455 case 0:
2456 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2457 "0470 Enable INTx interrupt mode.\n");
2458 break;
2459 case 1:
2460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2461 "0481 Enabled MSI interrupt mode.\n");
2462 break;
2463 case 2:
2464 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2465 "0480 Enabled MSI-X interrupt mode.\n");
2466 break;
2467 default:
2468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2469 "0482 Illegal interrupt mode.\n");
2470 break;
2471 }
2472 return;
2473}
2474
2475static void
2476lpfc_stop_port(struct lpfc_hba *phba)
2477{
2478 /* Clear all interrupt enable conditions */
2479 writel(0, phba->HCregaddr);
2480 readl(phba->HCregaddr); /* flush */
2481 /* Clear all pending interrupts */
2482 writel(0xffffffff, phba->HAregaddr);
2483 readl(phba->HAregaddr); /* flush */
2484
2485 /* Reset some HBA SLI setup states */
2486 lpfc_stop_phba_timers(phba);
2487 phba->pport->work_port_events = 0;
2488
2489 return;
2490}
2491
2492/**
2493 * lpfc_enable_intr: Enable device interrupt.
2494 * @phba: pointer to lpfc hba data structure.
2495 *
2496 * This routine is invoked to enable device interrupt and associate driver's
2497 * interrupt handler(s) to interrupt vector(s). Depends on the interrupt
2498 * mode configured to the driver, the driver will try to fallback from the
2499 * configured interrupt mode to an interrupt mode which is supported by the
2500 * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ.
2501 *
2502 * Return codes
2503 * 0 - sucessful
2504 * other values - error
2505 **/
2506static uint32_t
2507lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
2508{
2509 uint32_t intr_mode = LPFC_INTR_ERROR;
2510 int retval;
2511
2512 if (cfg_mode == 2) {
2513 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
2514 retval = lpfc_sli_config_port(phba, 3);
2515 if (!retval) {
2516 /* Now, try to enable MSI-X interrupt mode */
2517 retval = lpfc_enable_msix(phba);
2518 if (!retval) {
2519 /* Indicate initialization to MSI-X mode */
2520 phba->intr_type = MSIX;
2521 intr_mode = 2;
2522 }
2523 }
2524 }
2525
2526 /* Fallback to MSI if MSI-X initialization failed */
2527 if (cfg_mode >= 1 && phba->intr_type == NONE) {
2528 retval = lpfc_enable_msi(phba);
2529 if (!retval) {
2530 /* Indicate initialization to MSI mode */
2531 phba->intr_type = MSI;
2532 intr_mode = 1;
2533 }
2534 }
2535
2536 /* Fallback to INTx if both MSI-X/MSI initalization failed */
2537 if (phba->intr_type == NONE) {
2538 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2539 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2540 if (!retval) {
2541 /* Indicate initialization to INTx mode */
2542 phba->intr_type = INTx;
2543 intr_mode = 0;
2544 }
2545 }
2546 return intr_mode;
2547}
2548
2549/**
2550 * lpfc_disable_intr: Disable device interrupt.
2551 * @phba: pointer to lpfc hba data structure.
2552 *
2553 * This routine is invoked to disable device interrupt and disassociate the
2554 * driver's interrupt handler(s) from interrupt vector(s). Depending on the
2555 * interrupt mode, the driver will release the interrupt vector(s) for the
2556 * message signaled interrupt.
2557 **/
2558static void
2559lpfc_disable_intr(struct lpfc_hba *phba)
2560{
2561 /* Disable the currently initialized interrupt mode */
2562 if (phba->intr_type == MSIX)
2563 lpfc_disable_msix(phba);
2564 else if (phba->intr_type == MSI)
2565 lpfc_disable_msi(phba);
2566 else if (phba->intr_type == INTx)
2567 free_irq(phba->pcidev->irq, phba);
2568
2569 /* Reset interrupt management states */
2570 phba->intr_type = NONE;
2571 phba->sli.slistat.sli_intr = 0;
2572
2573 return;
2574}
2575
2576/**
James Smarte59058c2008-08-24 21:49:00 -04002577 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2578 * @pdev: pointer to PCI device
2579 * @pid: pointer to PCI device identifier
2580 *
2581 * This routine is to be registered to the kernel's PCI subsystem. When an
2582 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2583 * PCI device-specific information of the device and driver to see if the
2584 * driver state that it can support this kind of device. If the match is
2585 * successful, the driver core invokes this routine. If this routine
2586 * determines it can claim the HBA, it does all the initialization that it
2587 * needs to do to handle the HBA properly.
2588 *
2589 * Return code
2590 * 0 - driver can claim the device
2591 * negative value - driver can not claim the device
2592 **/
dea31012005-04-17 16:05:31 -05002593static int __devinit
2594lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2595{
James Smart2e0fef82007-06-17 19:56:36 -05002596 struct lpfc_vport *vport = NULL;
2597 struct lpfc_hba *phba;
2598 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002599 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002600 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04002601 void *ptr;
dea31012005-04-17 16:05:31 -05002602 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04002603 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04002604 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05002605 uint16_t iotag;
James Smart5b75da22008-12-04 22:39:35 -05002606 uint32_t cfg_mode, intr_mode;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002607 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
James Smartea2151b2008-09-07 11:52:10 -04002608 struct lpfc_adapter_event_header adapter_event;
dea31012005-04-17 16:05:31 -05002609
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01002610 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05002611 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002612 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05002613 goto out_disable_device;
2614
James Smart2e0fef82007-06-17 19:56:36 -05002615 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2616 if (!phba)
dea31012005-04-17 16:05:31 -05002617 goto out_release_regions;
2618
James Smartea2151b2008-09-07 11:52:10 -04002619 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002620 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002621
James Smarte47c9092008-02-08 18:49:26 -05002622 /* Initialize ndlp management spinlock */
2623 spin_lock_init(&phba->ndlp_lock);
2624
dea31012005-04-17 16:05:31 -05002625 phba->pcidev = pdev;
2626
2627 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05002628 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05002629 goto out_free_phba;
dea31012005-04-17 16:05:31 -05002630
James Smart2e0fef82007-06-17 19:56:36 -05002631 INIT_LIST_HEAD(&phba->port_list);
James Smart84774a42008-08-24 21:50:06 -04002632 init_waitqueue_head(&phba->wait_4_mlo_m_q);
James Smart2e0fef82007-06-17 19:56:36 -05002633 /*
2634 * Get all the module params for configuring this host and then
2635 * establish the host.
2636 */
2637 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002638 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002639
2640 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05002641 init_timer(&phba->hb_tmofunc);
2642 phba->hb_tmofunc.function = lpfc_hb_timeout;
2643 phba->hb_tmofunc.data = (unsigned long)phba;
2644
dea31012005-04-17 16:05:31 -05002645 psli = &phba->sli;
2646 init_timer(&psli->mbox_tmo);
2647 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002648 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002649 init_timer(&phba->fcp_poll_timer);
2650 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002651 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002652 init_timer(&phba->fabric_block_timer);
2653 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2654 phba->fabric_block_timer.data = (unsigned long) phba;
James Smart93996272008-08-24 21:50:30 -04002655 init_timer(&phba->eratt_poll);
2656 phba->eratt_poll.function = lpfc_poll_eratt;
2657 phba->eratt_poll.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002658
dea31012005-04-17 16:05:31 -05002659 pci_set_master(pdev);
James Smart97207482008-12-04 22:39:19 -05002660 pci_save_state(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002661 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002662
2663 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2664 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2665 goto out_idr_remove;
2666
2667 /*
2668 * Get the bus address of Bar0 and Bar2 and the number of bytes
2669 * required by each mapping.
2670 */
2671 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2672 bar0map_len = pci_resource_len(phba->pcidev, 0);
2673
2674 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2675 bar2map_len = pci_resource_len(phba->pcidev, 2);
2676
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002677 /* Map HBA SLIM to a kernel virtual address. */
James Smart93996272008-08-24 21:50:30 -04002678 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002679 if (!phba->slim_memmap_p) {
2680 error = -ENODEV;
2681 dev_printk(KERN_ERR, &pdev->dev,
2682 "ioremap failed for SLIM memory.\n");
2683 goto out_idr_remove;
2684 }
2685
2686 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002687 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002688 if (!phba->ctrl_regs_memmap_p) {
2689 error = -ENODEV;
2690 dev_printk(KERN_ERR, &pdev->dev,
2691 "ioremap failed for HBA control registers.\n");
2692 goto out_iounmap_slim;
2693 }
dea31012005-04-17 16:05:31 -05002694
2695 /* Allocate memory for SLI-2 structures */
James Smart34b02dc2008-08-24 21:49:55 -04002696 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2697 SLI2_SLIM_SIZE,
2698 &phba->slim2p.phys,
2699 GFP_KERNEL);
2700 if (!phba->slim2p.virt)
dea31012005-04-17 16:05:31 -05002701 goto out_iounmap;
2702
James Smart34b02dc2008-08-24 21:49:55 -04002703 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
James Smartd7c255b2008-08-24 21:50:00 -04002704 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
2705 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
2706 phba->IOCBs = (phba->slim2p.virt +
2707 offsetof(struct lpfc_sli2_slim, IOCBs));
dea31012005-04-17 16:05:31 -05002708
James Smarted957682007-06-17 19:56:37 -05002709 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2710 lpfc_sli_hbq_size(),
2711 &phba->hbqslimp.phys,
2712 GFP_KERNEL);
2713 if (!phba->hbqslimp.virt)
2714 goto out_free_slim;
2715
James Smart51ef4c22007-08-02 11:10:31 -04002716 hbq_count = lpfc_sli_hbq_count();
2717 ptr = phba->hbqslimp.virt;
2718 for (i = 0; i < hbq_count; ++i) {
2719 phba->hbqs[i].hbq_virt = ptr;
2720 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2721 ptr += (lpfc_hbq_defs[i]->entry_count *
2722 sizeof(struct lpfc_hbq_entry));
2723 }
2724 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2725 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2726
James Smarted957682007-06-17 19:56:37 -05002727 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2728
James Smart3163f722008-02-08 18:50:25 -05002729 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2730
dea31012005-04-17 16:05:31 -05002731 /* Initialize the SLI Layer to run with lpfc HBAs. */
2732 lpfc_sli_setup(phba);
2733 lpfc_sli_queue_setup(phba);
2734
James Smart98c9ea52007-10-27 13:37:33 -04002735 retval = lpfc_mem_alloc(phba);
2736 if (retval) {
2737 error = retval;
James Smarted957682007-06-17 19:56:37 -05002738 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002739 }
dea31012005-04-17 16:05:31 -05002740
2741 /* Initialize and populate the iocb list per host. */
2742 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2743 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002744 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002745 if (iocbq_entry == NULL) {
2746 printk(KERN_ERR "%s: only allocated %d iocbs of "
2747 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002748 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002749 error = -ENOMEM;
2750 goto out_free_iocbq;
2751 }
2752
James Bottomley604a3e32005-10-29 10:28:33 -05002753 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2754 if (iotag == 0) {
2755 kfree (iocbq_entry);
2756 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2757 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002758 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002759 error = -ENOMEM;
2760 goto out_free_iocbq;
2761 }
James Smart2e0fef82007-06-17 19:56:36 -05002762
2763 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002764 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2765 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002766 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002767 }
2768
2769 /* Initialize HBA structure */
2770 phba->fc_edtov = FF_DEF_EDTOV;
2771 phba->fc_ratov = FF_DEF_RATOV;
2772 phba->fc_altov = FF_DEF_ALTOV;
2773 phba->fc_arbtov = FF_DEF_ARBTOV;
2774
2775 INIT_LIST_HEAD(&phba->work_list);
James Smart93996272008-08-24 21:50:30 -04002776 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
dea31012005-04-17 16:05:31 -05002777 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2778
James Smart5e9d9b82008-06-14 22:52:53 -04002779 /* Initialize the wait queue head for the kernel thread */
2780 init_waitqueue_head(&phba->work_waitq);
2781
dea31012005-04-17 16:05:31 -05002782 /* Startup the kernel thread for this host adapter. */
2783 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2784 "lpfc_worker_%d", phba->brd_no);
2785 if (IS_ERR(phba->worker_thread)) {
2786 error = PTR_ERR(phba->worker_thread);
2787 goto out_free_iocbq;
2788 }
2789
dea31012005-04-17 16:05:31 -05002790 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002791 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002792 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2793
James Smart92d7f7b2007-06-17 19:56:38 -05002794 /* Initialize list of fabric iocbs */
2795 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2796
James Smart0ff10d42008-01-11 01:52:36 -05002797 /* Initialize list to save ELS buffers */
2798 INIT_LIST_HEAD(&phba->elsbuf);
2799
James Smart3de2a652007-08-02 11:09:59 -04002800 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002801 if (!vport)
2802 goto out_kthread_stop;
2803
2804 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002805 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002806 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002807
James Smart92d7f7b2007-06-17 19:56:38 -05002808 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05002809
James Smart93996272008-08-24 21:50:30 -04002810 phba->MBslimaddr = phba->slim_memmap_p;
2811 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2812 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2813 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2814 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2815
James Smart5b75da22008-12-04 22:39:35 -05002816 /* Configure sysfs attributes */
James Smart98c9ea52007-10-27 13:37:33 -04002817 if (lpfc_alloc_sysfs_attr(vport)) {
James Smart93996272008-08-24 21:50:30 -04002818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2819 "1476 Failed to allocate sysfs attr\n");
James Smart98c9ea52007-10-27 13:37:33 -04002820 error = -ENOMEM;
James Smart5b75da22008-12-04 22:39:35 -05002821 goto out_destroy_port;
James Smart98c9ea52007-10-27 13:37:33 -04002822 }
dea31012005-04-17 16:05:31 -05002823
James Smart5b75da22008-12-04 22:39:35 -05002824 cfg_mode = phba->cfg_use_msi;
2825 while (true) {
2826 /* Configure and enable interrupt */
2827 intr_mode = lpfc_enable_intr(phba, cfg_mode);
2828 if (intr_mode == LPFC_INTR_ERROR) {
2829 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2830 "0426 Failed to enable interrupt.\n");
2831 goto out_free_sysfs_attr;
2832 }
2833 /* HBA SLI setup */
2834 if (lpfc_sli_hba_setup(phba)) {
2835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2836 "1477 Failed to set up hba\n");
2837 error = -ENODEV;
2838 goto out_remove_device;
2839 }
2840
2841 /* Wait 50ms for the interrupts of previous mailbox commands */
2842 msleep(50);
2843 /* Check active interrupts received */
2844 if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
2845 /* Log the current active interrupt mode */
2846 phba->intr_mode = intr_mode;
2847 lpfc_log_intr_mode(phba, intr_mode);
2848 break;
2849 } else {
2850 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2851 "0451 Configure interrupt mode (%d) "
2852 "failed active interrupt test.\n",
2853 intr_mode);
2854 if (intr_mode == 0) {
2855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2856 "0479 Failed to enable "
2857 "interrupt.\n");
2858 error = -ENODEV;
2859 goto out_remove_device;
2860 }
2861 /* Stop HBA SLI setups */
2862 lpfc_stop_port(phba);
2863 /* Disable the current interrupt mode */
2864 lpfc_disable_intr(phba);
2865 /* Try next level of interrupt mode */
2866 cfg_mode = --intr_mode;
2867 }
James Smart98c9ea52007-10-27 13:37:33 -04002868 }
James Smart858c9f62007-06-17 19:56:39 -05002869
2870 /*
2871 * hba setup may have changed the hba_queue_depth so we need to adjust
2872 * the value of can_queue.
2873 */
2874 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart81301a92008-12-04 22:39:46 -05002875 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
2876
2877 if (lpfc_prot_mask && lpfc_prot_guard) {
2878 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2879 "1478 Registering BlockGuard with the "
2880 "SCSI layer\n");
2881
2882 scsi_host_set_prot(shost, lpfc_prot_mask);
2883 scsi_host_set_guard(shost, lpfc_prot_guard);
2884 }
2885 }
2886
2887 if (!_dump_buf_data) {
2888 int pagecnt = 10;
2889 while (pagecnt) {
2890 spin_lock_init(&_dump_buf_lock);
2891 _dump_buf_data =
2892 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
2893 if (_dump_buf_data) {
2894 printk(KERN_ERR "BLKGRD allocated %d pages for "
2895 "_dump_buf_data at 0x%p\n",
2896 (1 << pagecnt), _dump_buf_data);
2897 _dump_buf_data_order = pagecnt;
2898 memset(_dump_buf_data, 0, ((1 << PAGE_SHIFT)
2899 << pagecnt));
2900 break;
2901 } else {
2902 --pagecnt;
2903 }
2904
2905 }
2906
2907 if (!_dump_buf_data_order)
2908 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
2909 "memory for hexdump\n");
2910
2911 } else {
2912 printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p"
2913 "\n", _dump_buf_data);
2914 }
2915
2916
2917 if (!_dump_buf_dif) {
2918 int pagecnt = 10;
2919 while (pagecnt) {
2920 _dump_buf_dif =
2921 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
2922 if (_dump_buf_dif) {
2923 printk(KERN_ERR "BLKGRD allocated %d pages for "
2924 "_dump_buf_dif at 0x%p\n",
2925 (1 << pagecnt), _dump_buf_dif);
2926 _dump_buf_dif_order = pagecnt;
2927 memset(_dump_buf_dif, 0, ((1 << PAGE_SHIFT)
2928 << pagecnt));
2929 break;
2930 } else {
2931 --pagecnt;
2932 }
2933
2934 }
2935
2936 if (!_dump_buf_dif_order)
2937 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
2938 "memory for hexdump\n");
2939
2940 } else {
2941 printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n",
2942 _dump_buf_dif);
2943 }
James Smart858c9f62007-06-17 19:56:39 -05002944
2945 lpfc_host_attrib_init(shost);
2946
James Smart2e0fef82007-06-17 19:56:36 -05002947 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2948 spin_lock_irq(shost->host_lock);
2949 lpfc_poll_start_timer(phba);
2950 spin_unlock_irq(shost->host_lock);
2951 }
James Smart8f6d98d2006-08-01 07:34:00 -04002952
James Smart93996272008-08-24 21:50:30 -04002953 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2954 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04002955 /* Send board arrival event to upper layer */
2956 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
2957 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
2958 fc_host_post_vendor_event(shost, fc_get_event_number(),
2959 sizeof(adapter_event),
2960 (char *) &adapter_event,
James Smartddcc50f2008-12-04 22:38:46 -05002961 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04002962
dea31012005-04-17 16:05:31 -05002963 return 0;
2964
James Smart858c9f62007-06-17 19:56:39 -05002965out_remove_device:
James Smart858c9f62007-06-17 19:56:39 -05002966 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002967 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002968 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002969 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002970 phba->pport->work_port_events = 0;
James Smart5b75da22008-12-04 22:39:35 -05002971 lpfc_disable_intr(phba);
James Smart9f1e1b52008-12-04 22:39:40 -05002972 lpfc_sli_hba_down(phba);
2973 lpfc_sli_brdrestart(phba);
James Smart5b75da22008-12-04 22:39:35 -05002974out_free_sysfs_attr:
2975 lpfc_free_sysfs_attr(vport);
2976out_destroy_port:
James Smart2e0fef82007-06-17 19:56:36 -05002977 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002978out_kthread_stop:
2979 kthread_stop(phba->worker_thread);
2980out_free_iocbq:
2981 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2982 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002983 kfree(iocbq_entry);
2984 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002985 }
2986 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002987out_free_hbqslimp:
James Smart34b02dc2008-08-24 21:49:55 -04002988 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2989 phba->hbqslimp.virt, phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002990out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04002991 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2992 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05002993out_iounmap:
2994 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002995out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002996 iounmap(phba->slim_memmap_p);
2997out_idr_remove:
2998 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002999out_free_phba:
3000 kfree(phba);
dea31012005-04-17 16:05:31 -05003001out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003002 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05003003out_disable_device:
3004 pci_disable_device(pdev);
3005out:
James Smartdefbcf12006-04-16 22:26:50 -04003006 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05003007 if (shost)
3008 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05003009 return error;
3010}
3011
James Smarte59058c2008-08-24 21:49:00 -04003012/**
3013 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
3014 * @pdev: pointer to PCI device
3015 *
3016 * This routine is to be registered to the kernel's PCI subsystem. When an
James Smart3a55b532008-12-04 22:38:54 -05003017 * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup
James Smarte59058c2008-08-24 21:49:00 -04003018 * for the HBA device to be removed from the PCI subsystem properly.
3019 **/
dea31012005-04-17 16:05:31 -05003020static void __devexit
3021lpfc_pci_remove_one(struct pci_dev *pdev)
3022{
James Smart2e0fef82007-06-17 19:56:36 -05003023 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3024 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05003025 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05003026 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05003027 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003028 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
3029
James Smart549e55c2007-08-02 11:09:51 -04003030 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04003031 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04003032 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003033
James Smart858c9f62007-06-17 19:56:39 -05003034 lpfc_free_sysfs_attr(vport);
3035
James Smart09372822008-01-11 01:52:54 -05003036 kthread_stop(phba->worker_thread);
3037
James Smarteada2722008-12-04 22:39:13 -05003038 /* Release all the vports against this physical port */
3039 vports = lpfc_create_vport_work_array(phba);
3040 if (vports != NULL)
3041 for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++)
3042 fc_vport_terminate(vports[i]->fc_vport);
3043 lpfc_destroy_vport_work_array(phba, vports);
3044
3045 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05003046 fc_remove_host(shost);
3047 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04003048 lpfc_cleanup(vport);
3049
James Smart2e0fef82007-06-17 19:56:36 -05003050 /*
3051 * Bring down the SLI Layer. This step disable all interrupts,
3052 * clears the rings, discards all mailbox commands, and resets
3053 * the HBA.
3054 */
3055 lpfc_sli_hba_down(phba);
3056 lpfc_sli_brdrestart(phba);
3057
James Smart92d7f7b2007-06-17 19:56:38 -05003058 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05003059 spin_lock_irq(&phba->hbalock);
3060 list_del_init(&vport->listentry);
3061 spin_unlock_irq(&phba->hbalock);
3062
James Smart858c9f62007-06-17 19:56:39 -05003063 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003064
James Smart5b75da22008-12-04 22:39:35 -05003065 /* Disable interrupt */
3066 lpfc_disable_intr(phba);
dea31012005-04-17 16:05:31 -05003067
3068 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05003069 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05003070
3071 /*
3072 * Call scsi_free before mem_free since scsi bufs are released to their
3073 * corresponding pools here.
3074 */
3075 lpfc_scsi_free(phba);
3076 lpfc_mem_free(phba);
3077
James Smart34b02dc2008-08-24 21:49:55 -04003078 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
3079 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05003080
James Smart2e0fef82007-06-17 19:56:36 -05003081 /* Free resources associated with SLI2 interface */
3082 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04003083 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05003084
3085 /* unmap adapter SLIM and Control Registers */
3086 iounmap(phba->ctrl_regs_memmap_p);
3087 iounmap(phba->slim_memmap_p);
3088
3089 idr_remove(&lpfc_hba_index, phba->brd_no);
3090
3091 kfree(phba);
3092
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003093 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05003094 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05003095}
3096
Linas Vepstas8d63f372007-02-14 14:28:36 -06003097/**
James Smart3a55b532008-12-04 22:38:54 -05003098 * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management.
3099 * @pdev: pointer to PCI device
3100 * @msg: power management message
3101 *
3102 * This routine is to be registered to the kernel's PCI subsystem to support
3103 * system Power Management (PM). When PM invokes this method, it quiesces the
3104 * device by stopping the driver's worker thread for the device, turning off
3105 * device's interrupt and DMA, and bring the device offline. Note that as the
3106 * driver implements the minimum PM requirements to a power-aware driver's PM
3107 * support for suspend/resume -- all the possible PM messages (SUSPEND,
3108 * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND
3109 * and the driver will fully reinitialize its device during resume() method
3110 * call, the driver will set device to PCI_D3hot state in PCI config space
3111 * instead of setting it according to the @msg provided by the PM.
3112 *
3113 * Return code
3114 * 0 - driver suspended the device
3115 * Error otherwise
3116 **/
3117static int
3118lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
3119{
3120 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3121 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3122
3123 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3124 "0473 PCI device Power Management suspend.\n");
3125
3126 /* Bring down the device */
3127 lpfc_offline_prep(phba);
3128 lpfc_offline(phba);
3129 kthread_stop(phba->worker_thread);
3130
3131 /* Disable interrupt from device */
3132 lpfc_disable_intr(phba);
3133
3134 /* Save device state to PCI config space */
3135 pci_save_state(pdev);
3136 pci_set_power_state(pdev, PCI_D3hot);
3137
3138 return 0;
3139}
3140
3141/**
3142 * lpfc_pci_resume_one: lpfc PCI func to resume device for power management.
3143 * @pdev: pointer to PCI device
3144 *
3145 * This routine is to be registered to the kernel's PCI subsystem to support
3146 * system Power Management (PM). When PM invokes this method, it restores
3147 * the device's PCI config space state and fully reinitializes the device
3148 * and brings it online. Note that as the driver implements the minimum PM
3149 * requirements to a power-aware driver's PM for suspend/resume -- all
3150 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
3151 * method call will be treated as SUSPEND and the driver will fully
3152 * reinitialize its device during resume() method call, the device will be
3153 * set to PCI_D0 directly in PCI config space before restoring the state.
3154 *
3155 * Return code
3156 * 0 - driver suspended the device
3157 * Error otherwise
3158 **/
3159static int
3160lpfc_pci_resume_one(struct pci_dev *pdev)
3161{
3162 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3163 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05003164 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003165 int error;
3166
3167 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3168 "0452 PCI device Power Management resume.\n");
3169
3170 /* Restore device state from PCI config space */
3171 pci_set_power_state(pdev, PCI_D0);
3172 pci_restore_state(pdev);
3173 if (pdev->is_busmaster)
3174 pci_set_master(pdev);
3175
3176 /* Startup the kernel thread for this host adapter. */
3177 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3178 "lpfc_worker_%d", phba->brd_no);
3179 if (IS_ERR(phba->worker_thread)) {
3180 error = PTR_ERR(phba->worker_thread);
3181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3182 "0434 PM resume failed to start worker "
3183 "thread: error=x%x.\n", error);
3184 return error;
3185 }
3186
James Smart5b75da22008-12-04 22:39:35 -05003187 /* Configure and enable interrupt */
3188 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3189 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05003190 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05003191 "0430 PM resume Failed to enable interrupt\n");
3192 return -EIO;
3193 } else
3194 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003195
3196 /* Restart HBA and bring it online */
3197 lpfc_sli_brdrestart(phba);
3198 lpfc_online(phba);
3199
James Smart5b75da22008-12-04 22:39:35 -05003200 /* Log the current active interrupt mode */
3201 lpfc_log_intr_mode(phba, phba->intr_mode);
3202
James Smart3a55b532008-12-04 22:38:54 -05003203 return 0;
3204}
3205
3206/**
James Smarte59058c2008-08-24 21:49:00 -04003207 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
3208 * @pdev: pointer to PCI device.
3209 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003210 *
James Smarte59058c2008-08-24 21:49:00 -04003211 * This routine is registered to the PCI subsystem for error handling. This
3212 * function is called by the PCI subsystem after a PCI bus error affecting
3213 * this device has been detected. When this function is invoked, it will
3214 * need to stop all the I/Os and interrupt(s) to the device. Once that is
3215 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
3216 * perform proper recovery as desired.
3217 *
3218 * Return codes
3219 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
3220 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
3221 **/
Linas Vepstas8d63f372007-02-14 14:28:36 -06003222static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
3223 pci_channel_state_t state)
3224{
James Smart51ef4c22007-08-02 11:10:31 -04003225 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3226 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003227 struct lpfc_sli *psli = &phba->sli;
3228 struct lpfc_sli_ring *pring;
3229
James Smarta8e497d2008-08-24 21:50:11 -04003230 if (state == pci_channel_io_perm_failure) {
3231 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3232 "0472 PCI channel I/O permanent failure\n");
3233 /* Block all SCSI devices' I/Os on the host */
3234 lpfc_scsi_dev_block(phba);
3235 /* Clean up all driver's outstanding SCSI I/Os */
3236 lpfc_sli_flush_fcp_rings(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003237 return PCI_ERS_RESULT_DISCONNECT;
James Smarta8e497d2008-08-24 21:50:11 -04003238 }
Linas Vepstas5daa49e2007-03-08 16:19:11 -06003239
Linas Vepstas8d63f372007-02-14 14:28:36 -06003240 pci_disable_device(pdev);
3241 /*
3242 * There may be I/Os dropped by the firmware.
3243 * Error iocb (I/O) on txcmplq and let the SCSI layer
3244 * retry it after re-establishing link.
3245 */
3246 pring = &psli->ring[psli->fcp_ring];
3247 lpfc_sli_abort_iocb_ring(phba, pring);
3248
James Smart5b75da22008-12-04 22:39:35 -05003249 /* Disable interrupt */
3250 lpfc_disable_intr(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003251
Linas Vepstas8d63f372007-02-14 14:28:36 -06003252 /* Request a slot reset. */
3253 return PCI_ERS_RESULT_NEED_RESET;
3254}
3255
3256/**
James Smarte59058c2008-08-24 21:49:00 -04003257 * lpfc_io_slot_reset: Restart a PCI device from scratch.
3258 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003259 *
James Smarte59058c2008-08-24 21:49:00 -04003260 * This routine is registered to the PCI subsystem for error handling. This is
3261 * called after PCI bus has been reset to restart the PCI card from scratch,
3262 * as if from a cold-boot. During the PCI subsystem error recovery, after the
3263 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
3264 * proper error recovery and then call this routine before calling the .resume
3265 * method to recover the device. This function will initialize the HBA device,
3266 * enable the interrupt, but it will just put the HBA to offline state without
3267 * passing any I/O traffic.
3268 *
3269 * Return codes
3270 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
3271 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06003272 */
3273static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
3274{
James Smart51ef4c22007-08-02 11:10:31 -04003275 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3276 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003277 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05003278 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003279
3280 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003281 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06003282 printk(KERN_ERR "lpfc: Cannot re-enable "
3283 "PCI device after reset.\n");
3284 return PCI_ERS_RESULT_DISCONNECT;
3285 }
3286
James Smart97207482008-12-04 22:39:19 -05003287 pci_restore_state(pdev);
3288 if (pdev->is_busmaster)
3289 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003290
James Smart92d7f7b2007-06-17 19:56:38 -05003291 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003292 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05003293 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003294
James Smart5b75da22008-12-04 22:39:35 -05003295 /* Configure and enable interrupt */
3296 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3297 if (intr_mode == LPFC_INTR_ERROR) {
3298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3299 "0427 Cannot re-enable interrupt after "
3300 "slot reset.\n");
3301 return PCI_ERS_RESULT_DISCONNECT;
3302 } else
3303 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003304
3305 /* Take device offline; this will perform cleanup */
3306 lpfc_offline(phba);
3307 lpfc_sli_brdrestart(phba);
3308
James Smart5b75da22008-12-04 22:39:35 -05003309 /* Log the current active interrupt mode */
3310 lpfc_log_intr_mode(phba, phba->intr_mode);
3311
Linas Vepstas8d63f372007-02-14 14:28:36 -06003312 return PCI_ERS_RESULT_RECOVERED;
3313}
3314
3315/**
James Smarte59058c2008-08-24 21:49:00 -04003316 * lpfc_io_resume: Resume PCI I/O operation.
3317 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06003318 *
James Smarte59058c2008-08-24 21:49:00 -04003319 * This routine is registered to the PCI subsystem for error handling. It is
3320 * called when kernel error recovery tells the lpfc driver that it is ok to
3321 * resume normal PCI operation after PCI bus error recovery. After this call,
3322 * traffic can start to flow from this device again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003323 */
3324static void lpfc_io_resume(struct pci_dev *pdev)
3325{
James Smart51ef4c22007-08-02 11:10:31 -04003326 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3327 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003328
James Smart58da1ff2008-04-07 10:15:56 -04003329 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003330}
3331
dea31012005-04-17 16:05:31 -05003332static struct pci_device_id lpfc_id_table[] = {
3333 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
3334 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04003335 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
3336 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003337 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
3338 PCI_ANY_ID, PCI_ANY_ID, },
3339 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
3340 PCI_ANY_ID, PCI_ANY_ID, },
3341 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
3342 PCI_ANY_ID, PCI_ANY_ID, },
3343 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
3344 PCI_ANY_ID, PCI_ANY_ID, },
3345 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
3346 PCI_ANY_ID, PCI_ANY_ID, },
3347 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
3348 PCI_ANY_ID, PCI_ANY_ID, },
3349 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
3350 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003351 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
3352 PCI_ANY_ID, PCI_ANY_ID, },
3353 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
3354 PCI_ANY_ID, PCI_ANY_ID, },
3355 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
3356 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003357 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
3358 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003359 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
3360 PCI_ANY_ID, PCI_ANY_ID, },
3361 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
3362 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003363 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
3364 PCI_ANY_ID, PCI_ANY_ID, },
3365 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
3366 PCI_ANY_ID, PCI_ANY_ID, },
3367 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
3368 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003369 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
3370 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003371 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
3372 PCI_ANY_ID, PCI_ANY_ID, },
3373 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
3374 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003375 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
3376 PCI_ANY_ID, PCI_ANY_ID, },
3377 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
3378 PCI_ANY_ID, PCI_ANY_ID, },
3379 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
3380 PCI_ANY_ID, PCI_ANY_ID, },
3381 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
3382 PCI_ANY_ID, PCI_ANY_ID, },
3383 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
3384 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003385 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
3386 PCI_ANY_ID, PCI_ANY_ID, },
3387 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
3388 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04003389 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
3390 PCI_ANY_ID, PCI_ANY_ID, },
3391 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
3392 PCI_ANY_ID, PCI_ANY_ID, },
3393 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
3394 PCI_ANY_ID, PCI_ANY_ID, },
3395 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
3396 PCI_ANY_ID, PCI_ANY_ID, },
3397 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
3398 PCI_ANY_ID, PCI_ANY_ID, },
3399 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
3400 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003401 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
3402 PCI_ANY_ID, PCI_ANY_ID, },
3403 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
3404 PCI_ANY_ID, PCI_ANY_ID, },
3405 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
3406 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003407 { 0 }
3408};
3409
3410MODULE_DEVICE_TABLE(pci, lpfc_id_table);
3411
Linas Vepstas8d63f372007-02-14 14:28:36 -06003412static struct pci_error_handlers lpfc_err_handler = {
3413 .error_detected = lpfc_io_error_detected,
3414 .slot_reset = lpfc_io_slot_reset,
3415 .resume = lpfc_io_resume,
3416};
3417
dea31012005-04-17 16:05:31 -05003418static struct pci_driver lpfc_driver = {
3419 .name = LPFC_DRIVER_NAME,
3420 .id_table = lpfc_id_table,
3421 .probe = lpfc_pci_probe_one,
3422 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05003423 .suspend = lpfc_pci_suspend_one,
3424 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05003425 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05003426};
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
3429 * lpfc_init: lpfc module initialization routine.
3430 *
3431 * This routine is to be invoked when the lpfc module is loaded into the
3432 * kernel. The special kernel macro module_init() is used to indicate the
3433 * role of this routine to the kernel as lpfc module entry point.
3434 *
3435 * Return codes
3436 * 0 - successful
3437 * -ENOMEM - FC attach transport failed
3438 * all others - failed
3439 */
dea31012005-04-17 16:05:31 -05003440static int __init
3441lpfc_init(void)
3442{
3443 int error = 0;
3444
3445 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003446 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05003447
James Smart7ee5d432007-10-27 13:37:17 -04003448 if (lpfc_enable_npiv) {
3449 lpfc_transport_functions.vport_create = lpfc_vport_create;
3450 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
3451 }
dea31012005-04-17 16:05:31 -05003452 lpfc_transport_template =
3453 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04003454 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05003455 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04003456 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04003457 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04003458 fc_attach_transport(&lpfc_vport_transport_functions);
3459 if (lpfc_vport_transport_template == NULL) {
3460 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003461 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04003462 }
James Smart7ee5d432007-10-27 13:37:17 -04003463 }
dea31012005-04-17 16:05:31 -05003464 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05003465 if (error) {
dea31012005-04-17 16:05:31 -05003466 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04003467 if (lpfc_enable_npiv)
3468 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05003469 }
dea31012005-04-17 16:05:31 -05003470
3471 return error;
3472}
3473
James Smarte59058c2008-08-24 21:49:00 -04003474/**
3475 * lpfc_exit: lpfc module removal routine.
3476 *
3477 * This routine is invoked when the lpfc module is removed from the kernel.
3478 * The special kernel macro module_exit() is used to indicate the role of
3479 * this routine to the kernel as lpfc module exit point.
3480 */
dea31012005-04-17 16:05:31 -05003481static void __exit
3482lpfc_exit(void)
3483{
3484 pci_unregister_driver(&lpfc_driver);
3485 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003486 if (lpfc_enable_npiv)
3487 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -05003488 if (_dump_buf_data) {
3489 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data "
3490 "at 0x%p\n",
3491 (1L << _dump_buf_data_order), _dump_buf_data);
3492 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
3493 }
3494
3495 if (_dump_buf_dif) {
3496 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif "
3497 "at 0x%p\n",
3498 (1L << _dump_buf_dif_order), _dump_buf_dif);
3499 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
3500 }
dea31012005-04-17 16:05:31 -05003501}
3502
3503module_init(lpfc_init);
3504module_exit(lpfc_exit);
3505MODULE_LICENSE("GPL");
3506MODULE_DESCRIPTION(LPFC_MODULE_DESC);
3507MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
3508MODULE_VERSION("0:" LPFC_DRIVER_VERSION);