blob: e07f12a0871b442ad0b55e51535dcd9a80960368 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
27#include <linux/kthread.h>
28#include <linux/pci.h>
29#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050030#include <linux/ctype.h>
dea31012005-04-17 16:05:31 -050031
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040032#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050033#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
36
37#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046#include "lpfc_version.h"
47
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050048static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050049static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
50static int lpfc_post_rcv_buf(struct lpfc_hba *);
51
52static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050053static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050054static DEFINE_IDR(lpfc_hba_index);
55
James Smarte59058c2008-08-24 21:49:00 -040056/**
57 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
58 * @phba: pointer to lpfc hba data structure.
59 *
60 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
61 * mailbox command. It retrieves the revision information from the HBA and
62 * collects the Vital Product Data (VPD) about the HBA for preparing the
63 * configuration of the HBA.
64 *
65 * Return codes:
66 * 0 - success.
67 * -ERESTART - requests the SLI layer to reset the HBA and try again.
68 * Any other value - indicates an error.
69 **/
dea31012005-04-17 16:05:31 -050070int
James Smart2e0fef82007-06-17 19:56:36 -050071lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050072{
73 lpfc_vpd_t *vp = &phba->vpd;
74 int i = 0, rc;
75 LPFC_MBOXQ_t *pmb;
76 MAILBOX_t *mb;
77 char *lpfc_vpd_data = NULL;
78 uint16_t offset = 0;
79 static char licensed[56] =
80 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040081 static int init_key = 1;
dea31012005-04-17 16:05:31 -050082
83 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
84 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050085 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050086 return -ENOMEM;
87 }
88
89 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050090 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050091
92 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040093 if (init_key) {
94 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050095
James Smart65a29c12006-07-06 15:50:50 -040096 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
97 *ptext = cpu_to_be32(*ptext);
98 init_key = 0;
99 }
dea31012005-04-17 16:05:31 -0500100
101 lpfc_read_nv(phba, pmb);
102 memset((char*)mb->un.varRDnvp.rsvd3, 0,
103 sizeof (mb->un.varRDnvp.rsvd3));
104 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
105 sizeof (licensed));
106
107 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
108
109 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500110 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400111 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500112 "error, mbxCmd x%x READ_NVPARM, "
113 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500114 mb->mbxCommand, mb->mbxStatus);
115 mempool_free(pmb, phba->mbox_mem_pool);
116 return -ERESTART;
117 }
118 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500119 sizeof(phba->wwnn));
120 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
121 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500122 }
123
James Smart92d7f7b2007-06-17 19:56:38 -0500124 phba->sli3_options = 0x0;
125
dea31012005-04-17 16:05:31 -0500126 /* Setup and issue mailbox READ REV command */
127 lpfc_read_rev(phba, pmb);
128 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
129 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400131 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500132 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500133 mb->mbxCommand, mb->mbxStatus);
134 mempool_free( pmb, phba->mbox_mem_pool);
135 return -ERESTART;
136 }
137
James Smart92d7f7b2007-06-17 19:56:38 -0500138
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500139 /*
140 * The value of rr must be 1 since the driver set the cv field to 1.
141 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500142 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500143 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500144 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400146 "0440 Adapter failed to init, READ_REV has "
147 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500148 mempool_free(pmb, phba->mbox_mem_pool);
149 return -ERESTART;
dea31012005-04-17 16:05:31 -0500150 }
151
James Smart495a7142008-06-14 22:52:59 -0400152 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
153 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500154 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400155 }
James Smarted957682007-06-17 19:56:37 -0500156
dea31012005-04-17 16:05:31 -0500157 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500158 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500159 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500160 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
161 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
162 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
163 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500164 vp->rev.biuRev = mb->un.varRdRev.biuRev;
165 vp->rev.smRev = mb->un.varRdRev.smRev;
166 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
167 vp->rev.endecRev = mb->un.varRdRev.endecRev;
168 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
169 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
170 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
171 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
172 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
173 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
174
James Smart92d7f7b2007-06-17 19:56:38 -0500175 /* If the sli feature level is less then 9, we must
176 * tear down all RPIs and VPIs on link down if NPIV
177 * is enabled.
178 */
179 if (vp->rev.feaLevelHigh < 9)
180 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
181
dea31012005-04-17 16:05:31 -0500182 if (lpfc_is_LC_HBA(phba->pcidev->device))
183 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
184 sizeof (phba->RandomData));
185
dea31012005-04-17 16:05:31 -0500186 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500187 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
188 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400189 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500190
191 do {
192 lpfc_dump_mem(phba, pmb, offset);
193 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
194
195 if (rc != MBX_SUCCESS) {
196 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400197 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500198 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500199 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500200 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500201 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500202 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
203 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400204 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
205 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500206 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500207 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500208 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
209 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500210
211 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500212out_free_mbox:
213 mempool_free(pmb, phba->mbox_mem_pool);
214 return 0;
215}
216
James Smarte59058c2008-08-24 21:49:00 -0400217/**
218 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
219 * @phba: pointer to lpfc hba data structure.
220 * @pmboxq: pointer to the driver internal queue element for mailbox command.
221 *
222 * This is the completion handler for driver's configuring asynchronous event
223 * mailbox command to the device. If the mailbox command returns successfully,
224 * it will set internal async event support flag to 1; otherwise, it will
225 * set internal async event support flag to 0.
226 **/
James Smart57127f12007-10-27 13:37:05 -0400227static void
228lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
229{
230 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
231 phba->temp_sensor_support = 1;
232 else
233 phba->temp_sensor_support = 0;
234 mempool_free(pmboxq, phba->mbox_mem_pool);
235 return;
236}
237
James Smarte59058c2008-08-24 21:49:00 -0400238/**
James Smart97207482008-12-04 22:39:19 -0500239 * lpfc_dump_wakeup_param_cmpl: Completion handler for dump memory mailbox
240 * command used for getting wake up parameters.
241 * @phba: pointer to lpfc hba data structure.
242 * @pmboxq: pointer to the driver internal queue element for mailbox command.
243 *
244 * This is the completion handler for dump mailbox command for getting
245 * wake up parameters. When this command complete, the response contain
246 * Option rom version of the HBA. This function translate the version number
247 * into a human readable string and store it in OptionROMVersion.
248 **/
249static void
250lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
251{
252 struct prog_id *prg;
253 uint32_t prog_id_word;
254 char dist = ' ';
255 /* character array used for decoding dist type. */
256 char dist_char[] = "nabx";
257
258 if (pmboxq->mb.mbxStatus != MBX_SUCCESS)
259 return;
260
261 prg = (struct prog_id *) &prog_id_word;
262
263 /* word 7 contain option rom version */
264 prog_id_word = pmboxq->mb.un.varWords[7];
265
266 /* Decode the Option rom version word to a readable string */
267 if (prg->dist < 4)
268 dist = dist_char[prg->dist];
269
270 if ((prg->dist == 3) && (prg->num == 0))
271 sprintf(phba->OptionROMVersion, "%d.%d%d",
272 prg->ver, prg->rev, prg->lev);
273 else
274 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
275 prg->ver, prg->rev, prg->lev,
276 dist, prg->num);
277 return;
278}
279
280/**
James Smarte59058c2008-08-24 21:49:00 -0400281 * lpfc_config_port_post: Perform lpfc initialization after config port.
282 * @phba: pointer to lpfc hba data structure.
283 *
284 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
285 * command call. It performs all internal resource and state setups on the
286 * port: post IOCB buffers, enable appropriate host interrupt attentions,
287 * ELS ring timers, etc.
288 *
289 * Return codes
290 * 0 - success.
291 * Any other value - error.
292 **/
dea31012005-04-17 16:05:31 -0500293int
James Smart2e0fef82007-06-17 19:56:36 -0500294lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500295{
James Smart2e0fef82007-06-17 19:56:36 -0500296 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500297 LPFC_MBOXQ_t *pmb;
298 MAILBOX_t *mb;
299 struct lpfc_dmabuf *mp;
300 struct lpfc_sli *psli = &phba->sli;
301 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500302 int i, j;
303 int rc;
dea31012005-04-17 16:05:31 -0500304
James Smart7af67052007-10-27 13:38:11 -0400305 spin_lock_irq(&phba->hbalock);
306 /*
307 * If the Config port completed correctly the HBA is not
308 * over heated any more.
309 */
310 if (phba->over_temp_state == HBA_OVER_TEMP)
311 phba->over_temp_state = HBA_NORMAL_TEMP;
312 spin_unlock_irq(&phba->hbalock);
313
dea31012005-04-17 16:05:31 -0500314 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
315 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500316 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500317 return -ENOMEM;
318 }
319 mb = &pmb->mb;
320
dea31012005-04-17 16:05:31 -0500321 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500322 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500323 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500324 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400326 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500327 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500328 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500329 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500330 mp = (struct lpfc_dmabuf *) pmb->context1;
331 mempool_free( pmb, phba->mbox_mem_pool);
332 lpfc_mbuf_free(phba, mp->virt, mp->phys);
333 kfree(mp);
334 return -EIO;
335 }
336
337 mp = (struct lpfc_dmabuf *) pmb->context1;
338
James Smart2e0fef82007-06-17 19:56:36 -0500339 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500340 lpfc_mbuf_free(phba, mp->virt, mp->phys);
341 kfree(mp);
342 pmb->context1 = NULL;
343
James Smarta12e07b2006-12-02 13:35:30 -0500344 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500345 u64_to_wwn(phba->cfg_soft_wwnn,
346 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400347 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500348 u64_to_wwn(phba->cfg_soft_wwpn,
349 vport->fc_sparam.portName.u.wwn);
350 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500351 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500352 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500353 sizeof (struct lpfc_name));
354 /* If no serial number in VPD data, use low 6 bytes of WWNN */
355 /* This should be consolidated into parse_vpd ? - mr */
356 if (phba->SerialNumber[0] == 0) {
357 uint8_t *outptr;
358
James Smart2e0fef82007-06-17 19:56:36 -0500359 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500360 for (i = 0; i < 12; i++) {
361 status = *outptr++;
362 j = ((status & 0xf0) >> 4);
363 if (j <= 9)
364 phba->SerialNumber[i] =
365 (char)((uint8_t) 0x30 + (uint8_t) j);
366 else
367 phba->SerialNumber[i] =
368 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
369 i++;
370 j = (status & 0xf);
371 if (j <= 9)
372 phba->SerialNumber[i] =
373 (char)((uint8_t) 0x30 + (uint8_t) j);
374 else
375 phba->SerialNumber[i] =
376 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
377 }
378 }
379
dea31012005-04-17 16:05:31 -0500380 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500381 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500382 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400384 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500385 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500386 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500387 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500388 mempool_free( pmb, phba->mbox_mem_pool);
389 return -EIO;
390 }
391
392 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
393 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
394 phba->cfg_hba_queue_depth =
395 mb->un.varRdConfig.max_xri + 1;
396
397 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500398
399 /* Get the default values for Model Name and Description */
400 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
401
402 if ((phba->cfg_link_speed > LINK_SPEED_10G)
403 || ((phba->cfg_link_speed == LINK_SPEED_1G)
404 && !(phba->lmt & LMT_1Gb))
405 || ((phba->cfg_link_speed == LINK_SPEED_2G)
406 && !(phba->lmt & LMT_2Gb))
407 || ((phba->cfg_link_speed == LINK_SPEED_4G)
408 && !(phba->lmt & LMT_4Gb))
409 || ((phba->cfg_link_speed == LINK_SPEED_8G)
410 && !(phba->lmt & LMT_8Gb))
411 || ((phba->cfg_link_speed == LINK_SPEED_10G)
412 && !(phba->lmt & LMT_10Gb))) {
413 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500414 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400415 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500416 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500417 phba->cfg_link_speed);
418 phba->cfg_link_speed = LINK_SPEED_AUTO;
419 }
420
James Smart2e0fef82007-06-17 19:56:36 -0500421 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500422
James Smart0b727fe2007-10-27 13:37:25 -0400423 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500424 if (psli->ring[psli->extra_ring].cmdringaddr)
425 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500426 if (psli->ring[psli->fcp_ring].cmdringaddr)
427 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
428 if (psli->ring[psli->next_ring].cmdringaddr)
429 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
430
431 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500432 if (phba->sli_rev != 3)
433 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500434
James Smart93996272008-08-24 21:50:30 -0400435 /*
436 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
437 */
438 if (phba->intr_type == MSIX) {
439 rc = lpfc_config_msi(phba, pmb);
440 if (rc) {
441 mempool_free(pmb, phba->mbox_mem_pool);
442 return -EIO;
443 }
444 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
445 if (rc != MBX_SUCCESS) {
446 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
447 "0352 Config MSI mailbox command "
448 "failed, mbxCmd x%x, mbxStatus x%x\n",
449 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
450 mempool_free(pmb, phba->mbox_mem_pool);
451 return -EIO;
452 }
453 }
454
455 /* Initialize ERATT handling flag */
456 phba->hba_flag &= ~HBA_ERATT_HANDLED;
457
dea31012005-04-17 16:05:31 -0500458 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500459 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500460 status = readl(phba->HCregaddr);
461 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
462 if (psli->num_rings > 0)
463 status |= HC_R0INT_ENA;
464 if (psli->num_rings > 1)
465 status |= HC_R1INT_ENA;
466 if (psli->num_rings > 2)
467 status |= HC_R2INT_ENA;
468 if (psli->num_rings > 3)
469 status |= HC_R3INT_ENA;
470
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500471 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
472 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400473 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500474
dea31012005-04-17 16:05:31 -0500475 writel(status, phba->HCregaddr);
476 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500477 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500478
James Smart93996272008-08-24 21:50:30 -0400479 /* Set up ring-0 (ELS) timer */
480 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500481 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400482 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500483 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
484 phba->hb_outstanding = 0;
485 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400486 /* Set up error attention (ERATT) polling timer */
487 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500488
489 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
490 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400491 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400492 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400493 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500494 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400495 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500496 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500497 mb->mbxCommand, mb->mbxStatus);
498
499 /* Clear all interrupt enable conditions */
500 writel(0, phba->HCregaddr);
501 readl(phba->HCregaddr); /* flush */
502 /* Clear all pending interrupts */
503 writel(0xffffffff, phba->HAregaddr);
504 readl(phba->HAregaddr); /* flush */
505
James Smart2e0fef82007-06-17 19:56:36 -0500506 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400507 if (rc != MBX_BUSY)
508 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500509 return -EIO;
510 }
511 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400512 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
513 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
514 pmb->mbox_cmpl = lpfc_config_async_cmpl;
515 pmb->vport = phba->pport;
516 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500517
James Smart57127f12007-10-27 13:37:05 -0400518 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
519 lpfc_printf_log(phba,
520 KERN_ERR,
521 LOG_INIT,
522 "0456 Adapter failed to issue "
523 "ASYNCEVT_ENABLE mbox status x%x \n.",
524 rc);
525 mempool_free(pmb, phba->mbox_mem_pool);
526 }
James Smart97207482008-12-04 22:39:19 -0500527
528 /* Get Option rom version */
529 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
530 lpfc_dump_wakeup_param(phba, pmb);
531 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
532 pmb->vport = phba->pport;
533 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
534
535 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
536 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
537 "to get Option ROM version status x%x\n.", rc);
538 mempool_free(pmb, phba->mbox_mem_pool);
539 }
540
James Smartd7c255b2008-08-24 21:50:00 -0400541 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400542}
543
James Smarte59058c2008-08-24 21:49:00 -0400544/**
545 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
546 * @phba: pointer to lpfc HBA data structure.
547 *
548 * This routine will do LPFC uninitialization before the HBA is reset when
549 * bringing down the SLI Layer.
550 *
551 * Return codes
552 * 0 - success.
553 * Any other value - error.
554 **/
dea31012005-04-17 16:05:31 -0500555int
James Smart2e0fef82007-06-17 19:56:36 -0500556lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500557{
James Smart1b32f6a2008-02-08 18:49:39 -0500558 struct lpfc_vport **vports;
559 int i;
dea31012005-04-17 16:05:31 -0500560 /* Disable interrupts */
561 writel(0, phba->HCregaddr);
562 readl(phba->HCregaddr); /* flush */
563
James Smart1b32f6a2008-02-08 18:49:39 -0500564 if (phba->pport->load_flag & FC_UNLOADING)
565 lpfc_cleanup_discovery_resources(phba->pport);
566 else {
567 vports = lpfc_create_vport_work_array(phba);
568 if (vports != NULL)
569 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
570 lpfc_cleanup_discovery_resources(vports[i]);
571 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500572 }
573 return 0;
dea31012005-04-17 16:05:31 -0500574}
575
James Smarte59058c2008-08-24 21:49:00 -0400576/**
577 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
578 * @phba: pointer to lpfc HBA data structure.
579 *
580 * This routine will do uninitialization after the HBA is reset when bring
581 * down the SLI Layer.
582 *
583 * Return codes
584 * 0 - sucess.
585 * Any other value - error.
586 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500587int
James Smart2e0fef82007-06-17 19:56:36 -0500588lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500589{
590 struct lpfc_sli *psli = &phba->sli;
591 struct lpfc_sli_ring *pring;
592 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500593 struct lpfc_iocbq *iocb;
594 IOCB_t *cmd = NULL;
595 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500596 int i;
597
James Smart92d7f7b2007-06-17 19:56:38 -0500598 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
599 lpfc_sli_hbqbuf_free_all(phba);
600 else {
601 /* Cleanup preposted buffers on the ELS ring */
602 pring = &psli->ring[LPFC_ELS_RING];
603 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
604 list_del(&mp->list);
605 pring->postbufq_cnt--;
606 lpfc_mbuf_free(phba, mp->virt, mp->phys);
607 kfree(mp);
608 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500609 }
610
James Smart09372822008-01-11 01:52:54 -0500611 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500612 for (i = 0; i < psli->num_rings; i++) {
613 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500614
615 /* At this point in time the HBA is either reset or DOA. Either
616 * way, nothing should be on txcmplq as it will NEVER complete.
617 */
618 list_splice_init(&pring->txcmplq, &completions);
619 pring->txcmplq_cnt = 0;
620 spin_unlock_irq(&phba->hbalock);
621
622 while (!list_empty(&completions)) {
623 iocb = list_get_first(&completions, struct lpfc_iocbq,
624 list);
625 cmd = &iocb->iocb;
626 list_del_init(&iocb->list);
627
628 if (!iocb->iocb_cmpl)
629 lpfc_sli_release_iocbq(phba, iocb);
630 else {
631 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
632 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
633 (iocb->iocb_cmpl) (phba, iocb, iocb);
634 }
635 }
636
Jamie Wellnitz41415862006-02-28 19:25:27 -0500637 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500638 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500639 }
James Smart09372822008-01-11 01:52:54 -0500640 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500641
642 return 0;
643}
644
James Smarte59058c2008-08-24 21:49:00 -0400645/**
646 * lpfc_hb_timeout: The HBA-timer timeout handler.
647 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
648 *
649 * This is the HBA-timer timeout handler registered to the lpfc driver. When
650 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
651 * work-port-events bitmap and the worker thread is notified. This timeout
652 * event will be used by the worker thread to invoke the actual timeout
653 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
654 * be performed in the timeout handler and the HBA timeout event bit shall
655 * be cleared by the worker thread after it has taken the event bitmap out.
656 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100657static void
James Smart858c9f62007-06-17 19:56:39 -0500658lpfc_hb_timeout(unsigned long ptr)
659{
660 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400661 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500662 unsigned long iflag;
663
664 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400665
666 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500667 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400668 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
669 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500670 phba->pport->work_port_events |= WORKER_HB_TMO;
671 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
672
James Smart93996272008-08-24 21:50:30 -0400673 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400674 if (!tmo_posted)
675 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500676 return;
677}
678
James Smarte59058c2008-08-24 21:49:00 -0400679/**
680 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
681 * @phba: pointer to lpfc hba data structure.
682 * @pmboxq: pointer to the driver internal queue element for mailbox command.
683 *
684 * This is the callback function to the lpfc heart-beat mailbox command.
685 * If configured, the lpfc driver issues the heart-beat mailbox command to
686 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
687 * heart-beat mailbox command is issued, the driver shall set up heart-beat
688 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
689 * heart-beat outstanding state. Once the mailbox command comes back and
690 * no error conditions detected, the heart-beat mailbox command timer is
691 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
692 * state is cleared for the next heart-beat. If the timer expired with the
693 * heart-beat outstanding state set, the driver will put the HBA offline.
694 **/
James Smart858c9f62007-06-17 19:56:39 -0500695static void
696lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
697{
698 unsigned long drvr_flag;
699
700 spin_lock_irqsave(&phba->hbalock, drvr_flag);
701 phba->hb_outstanding = 0;
702 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
703
James Smart93996272008-08-24 21:50:30 -0400704 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -0500705 mempool_free(pmboxq, phba->mbox_mem_pool);
706 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
707 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400708 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500709 mod_timer(&phba->hb_tmofunc,
710 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
711 return;
712}
713
James Smarte59058c2008-08-24 21:49:00 -0400714/**
715 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
716 * @phba: pointer to lpfc hba data structure.
717 *
718 * This is the actual HBA-timer timeout handler to be invoked by the worker
719 * thread whenever the HBA timer fired and HBA-timeout event posted. This
720 * handler performs any periodic operations needed for the device. If such
721 * periodic event has already been attended to either in the interrupt handler
722 * or by processing slow-ring or fast-ring events within the HBA-timer
723 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
724 * the timer for the next timeout period. If lpfc heart-beat mailbox command
725 * is configured and there is no heart-beat mailbox command outstanding, a
726 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
727 * has been a heart-beat mailbox command outstanding, the HBA shall be put
728 * to offline.
729 **/
James Smart858c9f62007-06-17 19:56:39 -0500730void
731lpfc_hb_timeout_handler(struct lpfc_hba *phba)
732{
733 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500734 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500735 int retval;
736 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500737 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500738
739 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400740 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500741 (phba->pport->fc_flag & FC_OFFLINE_MODE))
742 return;
743
744 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -0500745
746 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
747 jiffies)) {
748 spin_unlock_irq(&phba->pport->work_port_lock);
749 if (!phba->hb_outstanding)
750 mod_timer(&phba->hb_tmofunc,
751 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
752 else
753 mod_timer(&phba->hb_tmofunc,
754 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
755 return;
756 }
757 spin_unlock_irq(&phba->pport->work_port_lock);
758
James Smart0ff10d42008-01-11 01:52:36 -0500759 if (phba->elsbuf_cnt &&
760 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
761 spin_lock_irq(&phba->hbalock);
762 list_splice_init(&phba->elsbuf, &completions);
763 phba->elsbuf_cnt = 0;
764 phba->elsbuf_prev_cnt = 0;
765 spin_unlock_irq(&phba->hbalock);
766
767 while (!list_empty(&completions)) {
768 list_remove_head(&completions, buf_ptr,
769 struct lpfc_dmabuf, list);
770 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
771 kfree(buf_ptr);
772 }
773 }
774 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
775
James Smart858c9f62007-06-17 19:56:39 -0500776 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500777 if (phba->cfg_enable_hba_heartbeat) {
778 if (!phba->hb_outstanding) {
779 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
780 if (!pmboxq) {
781 mod_timer(&phba->hb_tmofunc,
782 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
783 return;
784 }
785
786 lpfc_heart_beat(phba, pmboxq);
787 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
788 pmboxq->vport = phba->pport;
789 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
790
791 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
792 mempool_free(pmboxq, phba->mbox_mem_pool);
793 mod_timer(&phba->hb_tmofunc,
794 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
795 return;
796 }
James Smart858c9f62007-06-17 19:56:39 -0500797 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500798 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
799 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500800 return;
James Smart13815c82008-01-11 01:52:48 -0500801 } else {
802 /*
803 * If heart beat timeout called with hb_outstanding set
804 * we need to take the HBA offline.
805 */
806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
807 "0459 Adapter heartbeat failure, "
808 "taking this port offline.\n");
809
810 spin_lock_irq(&phba->hbalock);
811 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
812 spin_unlock_irq(&phba->hbalock);
813
814 lpfc_offline_prep(phba);
815 lpfc_offline(phba);
816 lpfc_unblock_mgmt_io(phba);
817 phba->link_state = LPFC_HBA_ERROR;
818 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500819 }
James Smart858c9f62007-06-17 19:56:39 -0500820 }
821}
822
James Smarte59058c2008-08-24 21:49:00 -0400823/**
824 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
825 * @phba: pointer to lpfc hba data structure.
826 *
827 * This routine is called to bring the HBA offline when HBA hardware error
828 * other than Port Error 6 has been detected.
829 **/
James Smart09372822008-01-11 01:52:54 -0500830static void
831lpfc_offline_eratt(struct lpfc_hba *phba)
832{
833 struct lpfc_sli *psli = &phba->sli;
834
835 spin_lock_irq(&phba->hbalock);
836 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
837 spin_unlock_irq(&phba->hbalock);
838 lpfc_offline_prep(phba);
839
840 lpfc_offline(phba);
841 lpfc_reset_barrier(phba);
842 lpfc_sli_brdreset(phba);
843 lpfc_hba_down_post(phba);
844 lpfc_sli_brdready(phba, HS_MBRDY);
845 lpfc_unblock_mgmt_io(phba);
846 phba->link_state = LPFC_HBA_ERROR;
847 return;
848}
849
James Smarte59058c2008-08-24 21:49:00 -0400850/**
851 * lpfc_handle_eratt: The HBA hardware error handler.
852 * @phba: pointer to lpfc hba data structure.
853 *
854 * This routine is invoked to handle the following HBA hardware error
855 * conditions:
856 * 1 - HBA error attention interrupt
857 * 2 - DMA ring index out of range
858 * 3 - Mailbox command came back as unknown
859 **/
dea31012005-04-17 16:05:31 -0500860void
James Smart2e0fef82007-06-17 19:56:36 -0500861lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500862{
James Smart2e0fef82007-06-17 19:56:36 -0500863 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500864 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500865 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400866 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400867 unsigned long temperature;
868 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500869 struct Scsi_Host *shost;
James Smartea2151b2008-09-07 11:52:10 -0400870 struct lpfc_board_event_header board_event;
James Smart2e0fef82007-06-17 19:56:36 -0500871
Linas Vepstas8d63f372007-02-14 14:28:36 -0600872 /* If the pci channel is offline, ignore possible errors,
873 * since we cannot communicate with the pci card anyway. */
874 if (pci_channel_offline(phba->pcidev))
875 return;
James Smart13815c82008-01-11 01:52:48 -0500876 /* If resets are disabled then leave the HBA alone and return */
877 if (!phba->cfg_enable_hba_reset)
878 return;
dea31012005-04-17 16:05:31 -0500879
James Smartea2151b2008-09-07 11:52:10 -0400880 /* Send an internal error event to mgmt application */
881 board_event.event_type = FC_REG_BOARD_EVENT;
882 board_event.subcategory = LPFC_EVENT_PORTINTERR;
883 shost = lpfc_shost_from_vport(phba->pport);
884 fc_host_post_vendor_event(shost, fc_get_event_number(),
885 sizeof(board_event),
886 (char *) &board_event,
James Smartddcc50f2008-12-04 22:38:46 -0500887 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400888
James Smart97eab632008-04-07 10:16:05 -0400889 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500890 /* Re-establishing Link */
891 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400892 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500893 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400894 phba->work_hs,
dea31012005-04-17 16:05:31 -0500895 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400896
James Smart92d7f7b2007-06-17 19:56:38 -0500897 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500898 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500899 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500900
901 /*
902 * Firmware stops when it triggled erratt with HS_FFER6.
903 * That could cause the I/Os dropped by the firmware.
904 * Error iocb (I/O) on txcmplq and let the SCSI layer
905 * retry it after re-establishing link.
906 */
907 pring = &psli->ring[psli->fcp_ring];
908 lpfc_sli_abort_iocb_ring(phba, pring);
909
dea31012005-04-17 16:05:31 -0500910 /*
911 * There was a firmware error. Take the hba offline and then
912 * attempt to restart it.
913 */
James Smart46fa3112007-04-25 09:51:45 -0400914 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500915 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500916 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500917 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400918 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500919 return;
920 }
James Smart46fa3112007-04-25 09:51:45 -0400921 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400922 } else if (phba->work_hs & HS_CRIT_TEMP) {
923 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
924 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
925 temp_event_data.event_code = LPFC_CRIT_TEMP;
926 temp_event_data.data = (uint32_t)temperature;
927
928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -0400929 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -0400930 "(%ld), taking this port offline "
931 "Data: x%x x%x x%x\n",
932 temperature, phba->work_hs,
933 phba->work_status[0], phba->work_status[1]);
934
935 shost = lpfc_shost_from_vport(phba->pport);
936 fc_host_post_vendor_event(shost, fc_get_event_number(),
937 sizeof(temp_event_data),
938 (char *) &temp_event_data,
939 SCSI_NL_VID_TYPE_PCI
940 | PCI_VENDOR_ID_EMULEX);
941
James Smart7af67052007-10-27 13:38:11 -0400942 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400943 phba->over_temp_state = HBA_OVER_TEMP;
944 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500945 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400946
dea31012005-04-17 16:05:31 -0500947 } else {
948 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -0400949 * failure is a value other than FFER6. Do not call the offline
950 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -0500951 */
952 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400953 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500954 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400955 phba->work_hs,
dea31012005-04-17 16:05:31 -0500956 phba->work_status[0], phba->work_status[1]);
957
James Smartd2873e42006-08-18 17:46:43 -0400958 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500959 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500960 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400961 sizeof(event_data), (char *) &event_data,
962 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
963
James Smart09372822008-01-11 01:52:54 -0500964 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500965 }
James Smart93996272008-08-24 21:50:30 -0400966 return;
dea31012005-04-17 16:05:31 -0500967}
968
James Smarte59058c2008-08-24 21:49:00 -0400969/**
970 * lpfc_handle_latt: The HBA link event handler.
971 * @phba: pointer to lpfc hba data structure.
972 *
973 * This routine is invoked from the worker thread to handle a HBA host
974 * attention link event.
975 **/
dea31012005-04-17 16:05:31 -0500976void
James Smart2e0fef82007-06-17 19:56:36 -0500977lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500978{
James Smart2e0fef82007-06-17 19:56:36 -0500979 struct lpfc_vport *vport = phba->pport;
980 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500981 LPFC_MBOXQ_t *pmb;
982 volatile uint32_t control;
983 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500984 int rc = 0;
dea31012005-04-17 16:05:31 -0500985
986 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500987 if (!pmb) {
988 rc = 1;
dea31012005-04-17 16:05:31 -0500989 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500990 }
dea31012005-04-17 16:05:31 -0500991
992 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500993 if (!mp) {
994 rc = 2;
dea31012005-04-17 16:05:31 -0500995 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500996 }
dea31012005-04-17 16:05:31 -0500997
998 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500999 if (!mp->virt) {
1000 rc = 3;
dea31012005-04-17 16:05:31 -05001001 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001002 }
dea31012005-04-17 16:05:31 -05001003
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001004 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001005 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001006
1007 psli->slistat.link_event++;
1008 lpfc_read_la(phba, pmb, mp);
1009 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -05001010 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001011 /* Block ELS IOCBs until we have processed this mbox command */
1012 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001013 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001014 if (rc == MBX_NOT_FINISHED) {
1015 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001016 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001017 }
dea31012005-04-17 16:05:31 -05001018
1019 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001020 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001021 writel(HA_LATT, phba->HAregaddr);
1022 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001023 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001024
1025 return;
1026
James Smart14691152006-12-02 13:34:28 -05001027lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001028 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001029 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001030lpfc_handle_latt_free_mp:
1031 kfree(mp);
1032lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001033 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001034lpfc_handle_latt_err_exit:
1035 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001036 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001037 psli->sli_flag |= LPFC_PROCESS_LA;
1038 control = readl(phba->HCregaddr);
1039 control |= HC_LAINT_ENA;
1040 writel(control, phba->HCregaddr);
1041 readl(phba->HCregaddr); /* flush */
1042
1043 /* Clear Link Attention in HA REG */
1044 writel(HA_LATT, phba->HAregaddr);
1045 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001046 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001047 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001048 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001049
James Smart09372822008-01-11 01:52:54 -05001050 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1051 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001052
1053 return;
1054}
1055
James Smarte59058c2008-08-24 21:49:00 -04001056/**
1057 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
1058 * @phba: pointer to lpfc hba data structure.
1059 * @vpd: pointer to the vital product data.
1060 * @len: length of the vital product data in bytes.
1061 *
1062 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1063 * an array of characters. In this routine, the ModelName, ProgramType, and
1064 * ModelDesc, etc. fields of the phba data structure will be populated.
1065 *
1066 * Return codes
1067 * 0 - pointer to the VPD passed in is NULL
1068 * 1 - success
1069 **/
dea31012005-04-17 16:05:31 -05001070static int
James Smart2e0fef82007-06-17 19:56:36 -05001071lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001072{
1073 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001074 int Length;
dea31012005-04-17 16:05:31 -05001075 int i, j;
1076 int finished = 0;
1077 int index = 0;
1078
1079 if (!vpd)
1080 return 0;
1081
1082 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001083 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001084 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001085 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1086 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001087 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001088 switch (vpd[index]) {
1089 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001090 case 0x91:
dea31012005-04-17 16:05:31 -05001091 index += 1;
1092 lenlo = vpd[index];
1093 index += 1;
1094 lenhi = vpd[index];
1095 index += 1;
1096 i = ((((unsigned short)lenhi) << 8) + lenlo);
1097 index += i;
1098 break;
1099 case 0x90:
1100 index += 1;
1101 lenlo = vpd[index];
1102 index += 1;
1103 lenhi = vpd[index];
1104 index += 1;
1105 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001106 if (Length > len - index)
1107 Length = len - index;
dea31012005-04-17 16:05:31 -05001108 while (Length > 0) {
1109 /* Look for Serial Number */
1110 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1111 index += 2;
1112 i = vpd[index];
1113 index += 1;
1114 j = 0;
1115 Length -= (3+i);
1116 while(i--) {
1117 phba->SerialNumber[j++] = vpd[index++];
1118 if (j == 31)
1119 break;
1120 }
1121 phba->SerialNumber[j] = 0;
1122 continue;
1123 }
1124 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1125 phba->vpd_flag |= VPD_MODEL_DESC;
1126 index += 2;
1127 i = vpd[index];
1128 index += 1;
1129 j = 0;
1130 Length -= (3+i);
1131 while(i--) {
1132 phba->ModelDesc[j++] = vpd[index++];
1133 if (j == 255)
1134 break;
1135 }
1136 phba->ModelDesc[j] = 0;
1137 continue;
1138 }
1139 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1140 phba->vpd_flag |= VPD_MODEL_NAME;
1141 index += 2;
1142 i = vpd[index];
1143 index += 1;
1144 j = 0;
1145 Length -= (3+i);
1146 while(i--) {
1147 phba->ModelName[j++] = vpd[index++];
1148 if (j == 79)
1149 break;
1150 }
1151 phba->ModelName[j] = 0;
1152 continue;
1153 }
1154 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1155 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1156 index += 2;
1157 i = vpd[index];
1158 index += 1;
1159 j = 0;
1160 Length -= (3+i);
1161 while(i--) {
1162 phba->ProgramType[j++] = vpd[index++];
1163 if (j == 255)
1164 break;
1165 }
1166 phba->ProgramType[j] = 0;
1167 continue;
1168 }
1169 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1170 phba->vpd_flag |= VPD_PORT;
1171 index += 2;
1172 i = vpd[index];
1173 index += 1;
1174 j = 0;
1175 Length -= (3+i);
1176 while(i--) {
1177 phba->Port[j++] = vpd[index++];
1178 if (j == 19)
1179 break;
1180 }
1181 phba->Port[j] = 0;
1182 continue;
1183 }
1184 else {
1185 index += 2;
1186 i = vpd[index];
1187 index += 1;
1188 index += i;
1189 Length -= (3 + i);
1190 }
1191 }
1192 finished = 0;
1193 break;
1194 case 0x78:
1195 finished = 1;
1196 break;
1197 default:
1198 index ++;
1199 break;
1200 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001201 }
dea31012005-04-17 16:05:31 -05001202
1203 return(1);
1204}
1205
James Smarte59058c2008-08-24 21:49:00 -04001206/**
1207 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1208 * @phba: pointer to lpfc hba data structure.
1209 * @mdp: pointer to the data structure to hold the derived model name.
1210 * @descp: pointer to the data structure to hold the derived description.
1211 *
1212 * This routine retrieves HBA's description based on its registered PCI device
1213 * ID. The @descp passed into this function points to an array of 256 chars. It
1214 * shall be returned with the model name, maximum speed, and the host bus type.
1215 * The @mdp passed into this function points to an array of 80 chars. When the
1216 * function returns, the @mdp will be filled with the model name.
1217 **/
dea31012005-04-17 16:05:31 -05001218static void
James Smart2e0fef82007-06-17 19:56:36 -05001219lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001220{
1221 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001222 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001223 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001224 int GE = 0;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001225 struct {
1226 char * name;
1227 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001228 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001229 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001230
1231 if (mdp && mdp[0] != '\0'
1232 && descp && descp[0] != '\0')
1233 return;
1234
1235 if (phba->lmt & LMT_10Gb)
1236 max_speed = 10;
1237 else if (phba->lmt & LMT_8Gb)
1238 max_speed = 8;
1239 else if (phba->lmt & LMT_4Gb)
1240 max_speed = 4;
1241 else if (phba->lmt & LMT_2Gb)
1242 max_speed = 2;
1243 else
1244 max_speed = 1;
dea31012005-04-17 16:05:31 -05001245
1246 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001247
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001248 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001249 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001250 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001251 break;
dea31012005-04-17 16:05:31 -05001252 case PCI_DEVICE_ID_SUPERFLY:
1253 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001254 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001255 else
James Smart18a3b592006-12-02 13:35:08 -05001256 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001257 break;
1258 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001259 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001260 break;
1261 case PCI_DEVICE_ID_CENTAUR:
1262 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001263 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001264 else
James Smart18a3b592006-12-02 13:35:08 -05001265 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001266 break;
1267 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001268 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001269 break;
1270 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001271 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001272 break;
1273 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001274 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001275 break;
1276 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001277 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001278 break;
1279 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001280 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001281 break;
1282 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001283 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001284 break;
1285 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001286 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001287 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001288 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001289 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001290 break;
1291 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001292 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001293 break;
1294 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001295 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001296 break;
1297 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001298 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001299 break;
1300 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001301 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001302 break;
dea31012005-04-17 16:05:31 -05001303 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001304 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001305 break;
1306 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001307 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001308 break;
1309 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001310 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001311 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001312 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001313 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001314 break;
1315 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001316 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001317 break;
dea31012005-04-17 16:05:31 -05001318 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001319 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001320 break;
1321 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001322 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001323 break;
1324 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001325 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001326 break;
1327 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001328 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001329 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001330 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001331 m = (typeof(m)){"LP11000-S", max_speed,
1332 "PCI-X2"};
1333 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001334 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001335 m = (typeof(m)){"LPe11000-S", max_speed,
1336 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001337 break;
James Smartb87eab32007-04-25 09:53:28 -04001338 case PCI_DEVICE_ID_SAT:
1339 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1340 break;
1341 case PCI_DEVICE_ID_SAT_MID:
1342 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1343 break;
1344 case PCI_DEVICE_ID_SAT_SMB:
1345 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1346 break;
1347 case PCI_DEVICE_ID_SAT_DCSP:
1348 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1349 break;
1350 case PCI_DEVICE_ID_SAT_SCSP:
1351 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1352 break;
1353 case PCI_DEVICE_ID_SAT_S:
1354 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1355 break;
James Smart84774a42008-08-24 21:50:06 -04001356 case PCI_DEVICE_ID_HORNET:
1357 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1358 GE = 1;
1359 break;
1360 case PCI_DEVICE_ID_PROTEUS_VF:
1361 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1362 break;
1363 case PCI_DEVICE_ID_PROTEUS_PF:
1364 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1365 break;
1366 case PCI_DEVICE_ID_PROTEUS_S:
1367 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1368 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001369 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001370 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001371 break;
dea31012005-04-17 16:05:31 -05001372 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001373
1374 if (mdp && mdp[0] == '\0')
1375 snprintf(mdp, 79,"%s", m.name);
1376 if (descp && descp[0] == '\0')
1377 snprintf(descp, 255,
James Smart84774a42008-08-24 21:50:06 -04001378 "Emulex %s %d%s %s %s",
1379 m.name, m.max_speed,
1380 (GE) ? "GE" : "Gb",
1381 m.bus,
1382 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
dea31012005-04-17 16:05:31 -05001383}
1384
James Smarte59058c2008-08-24 21:49:00 -04001385/**
1386 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1387 * @phba: pointer to lpfc hba data structure.
1388 * @pring: pointer to a IOCB ring.
1389 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1390 *
1391 * This routine posts a given number of IOCBs with the associated DMA buffer
1392 * descriptors specified by the cnt argument to the given IOCB ring.
1393 *
1394 * Return codes
1395 * The number of IOCBs NOT able to be posted to the IOCB ring.
1396 **/
dea31012005-04-17 16:05:31 -05001397int
James Smart495a7142008-06-14 22:52:59 -04001398lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001399{
1400 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001401 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001402 struct lpfc_dmabuf *mp1, *mp2;
1403
1404 cnt += pring->missbufcnt;
1405
1406 /* While there are buffers to post */
1407 while (cnt > 0) {
1408 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001409 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001410 if (iocb == NULL) {
1411 pring->missbufcnt = cnt;
1412 return cnt;
1413 }
dea31012005-04-17 16:05:31 -05001414 icmd = &iocb->iocb;
1415
1416 /* 2 buffers can be posted per command */
1417 /* Allocate buffer to post */
1418 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1419 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001420 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1421 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001422 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001423 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001424 pring->missbufcnt = cnt;
1425 return cnt;
1426 }
1427
1428 INIT_LIST_HEAD(&mp1->list);
1429 /* Allocate buffer to post */
1430 if (cnt > 1) {
1431 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1432 if (mp2)
1433 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1434 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001435 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001436 kfree(mp2);
dea31012005-04-17 16:05:31 -05001437 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1438 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001439 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001440 pring->missbufcnt = cnt;
1441 return cnt;
1442 }
1443
1444 INIT_LIST_HEAD(&mp2->list);
1445 } else {
1446 mp2 = NULL;
1447 }
1448
1449 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1450 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1451 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1452 icmd->ulpBdeCount = 1;
1453 cnt--;
1454 if (mp2) {
1455 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1456 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1457 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1458 cnt--;
1459 icmd->ulpBdeCount = 2;
1460 }
1461
1462 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1463 icmd->ulpLe = 1;
1464
dea31012005-04-17 16:05:31 -05001465 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1466 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1467 kfree(mp1);
1468 cnt++;
1469 if (mp2) {
1470 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1471 kfree(mp2);
1472 cnt++;
1473 }
James Bottomley604a3e32005-10-29 10:28:33 -05001474 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001475 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001476 return cnt;
1477 }
dea31012005-04-17 16:05:31 -05001478 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001479 if (mp2)
dea31012005-04-17 16:05:31 -05001480 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001481 }
1482 pring->missbufcnt = 0;
1483 return 0;
1484}
1485
James Smarte59058c2008-08-24 21:49:00 -04001486/**
1487 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1488 * @phba: pointer to lpfc hba data structure.
1489 *
1490 * This routine posts initial receive IOCB buffers to the ELS ring. The
1491 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1492 * set to 64 IOCBs.
1493 *
1494 * Return codes
1495 * 0 - success (currently always success)
1496 **/
dea31012005-04-17 16:05:31 -05001497static int
James Smart2e0fef82007-06-17 19:56:36 -05001498lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001499{
1500 struct lpfc_sli *psli = &phba->sli;
1501
1502 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001503 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001504 /* Ring 2 - FCP no buffers needed */
1505
1506 return 0;
1507}
1508
1509#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1510
James Smarte59058c2008-08-24 21:49:00 -04001511/**
1512 * lpfc_sha_init: Set up initial array of hash table entries.
1513 * @HashResultPointer: pointer to an array as hash table.
1514 *
1515 * This routine sets up the initial values to the array of hash table entries
1516 * for the LC HBAs.
1517 **/
dea31012005-04-17 16:05:31 -05001518static void
1519lpfc_sha_init(uint32_t * HashResultPointer)
1520{
1521 HashResultPointer[0] = 0x67452301;
1522 HashResultPointer[1] = 0xEFCDAB89;
1523 HashResultPointer[2] = 0x98BADCFE;
1524 HashResultPointer[3] = 0x10325476;
1525 HashResultPointer[4] = 0xC3D2E1F0;
1526}
1527
James Smarte59058c2008-08-24 21:49:00 -04001528/**
1529 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1530 * @HashResultPointer: pointer to an initial/result hash table.
1531 * @HashWorkingPointer: pointer to an working hash table.
1532 *
1533 * This routine iterates an initial hash table pointed by @HashResultPointer
1534 * with the values from the working hash table pointeed by @HashWorkingPointer.
1535 * The results are putting back to the initial hash table, returned through
1536 * the @HashResultPointer as the result hash table.
1537 **/
dea31012005-04-17 16:05:31 -05001538static void
1539lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1540{
1541 int t;
1542 uint32_t TEMP;
1543 uint32_t A, B, C, D, E;
1544 t = 16;
1545 do {
1546 HashWorkingPointer[t] =
1547 S(1,
1548 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1549 8] ^
1550 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1551 } while (++t <= 79);
1552 t = 0;
1553 A = HashResultPointer[0];
1554 B = HashResultPointer[1];
1555 C = HashResultPointer[2];
1556 D = HashResultPointer[3];
1557 E = HashResultPointer[4];
1558
1559 do {
1560 if (t < 20) {
1561 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1562 } else if (t < 40) {
1563 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1564 } else if (t < 60) {
1565 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1566 } else {
1567 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1568 }
1569 TEMP += S(5, A) + E + HashWorkingPointer[t];
1570 E = D;
1571 D = C;
1572 C = S(30, B);
1573 B = A;
1574 A = TEMP;
1575 } while (++t <= 79);
1576
1577 HashResultPointer[0] += A;
1578 HashResultPointer[1] += B;
1579 HashResultPointer[2] += C;
1580 HashResultPointer[3] += D;
1581 HashResultPointer[4] += E;
1582
1583}
1584
James Smarte59058c2008-08-24 21:49:00 -04001585/**
1586 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1587 * @RandomChallenge: pointer to the entry of host challenge random number array.
1588 * @HashWorking: pointer to the entry of the working hash array.
1589 *
1590 * This routine calculates the working hash array referred by @HashWorking
1591 * from the challenge random numbers associated with the host, referred by
1592 * @RandomChallenge. The result is put into the entry of the working hash
1593 * array and returned by reference through @HashWorking.
1594 **/
dea31012005-04-17 16:05:31 -05001595static void
1596lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1597{
1598 *HashWorking = (*RandomChallenge ^ *HashWorking);
1599}
1600
James Smarte59058c2008-08-24 21:49:00 -04001601/**
1602 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1603 * @phba: pointer to lpfc hba data structure.
1604 * @hbainit: pointer to an array of unsigned 32-bit integers.
1605 *
1606 * This routine performs the special handling for LC HBA initialization.
1607 **/
dea31012005-04-17 16:05:31 -05001608void
1609lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1610{
1611 int t;
1612 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001613 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001614
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001615 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001616 if (!HashWorking)
1617 return;
1618
dea31012005-04-17 16:05:31 -05001619 HashWorking[0] = HashWorking[78] = *pwwnn++;
1620 HashWorking[1] = HashWorking[79] = *pwwnn;
1621
1622 for (t = 0; t < 7; t++)
1623 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1624
1625 lpfc_sha_init(hbainit);
1626 lpfc_sha_iterate(hbainit, HashWorking);
1627 kfree(HashWorking);
1628}
1629
James Smarte59058c2008-08-24 21:49:00 -04001630/**
1631 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1632 * @vport: pointer to a virtual N_Port data structure.
1633 *
1634 * This routine performs the necessary cleanups before deleting the @vport.
1635 * It invokes the discovery state machine to perform necessary state
1636 * transitions and to release the ndlps associated with the @vport. Note,
1637 * the physical port is treated as @vport 0.
1638 **/
James Smart87af33f2007-10-27 13:37:43 -04001639void
James Smart2e0fef82007-06-17 19:56:36 -05001640lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001641{
James Smart87af33f2007-10-27 13:37:43 -04001642 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001643 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001644 int i = 0;
dea31012005-04-17 16:05:31 -05001645
James Smart87af33f2007-10-27 13:37:43 -04001646 if (phba->link_state > LPFC_LINK_DOWN)
1647 lpfc_port_link_failure(vport);
1648
1649 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001650 if (!NLP_CHK_NODE_ACT(ndlp)) {
1651 ndlp = lpfc_enable_node(vport, ndlp,
1652 NLP_STE_UNUSED_NODE);
1653 if (!ndlp)
1654 continue;
1655 spin_lock_irq(&phba->ndlp_lock);
1656 NLP_SET_FREE_REQ(ndlp);
1657 spin_unlock_irq(&phba->ndlp_lock);
1658 /* Trigger the release of the ndlp memory */
1659 lpfc_nlp_put(ndlp);
1660 continue;
1661 }
1662 spin_lock_irq(&phba->ndlp_lock);
1663 if (NLP_CHK_FREE_REQ(ndlp)) {
1664 /* The ndlp should not be in memory free mode already */
1665 spin_unlock_irq(&phba->ndlp_lock);
1666 continue;
1667 } else
1668 /* Indicate request for freeing ndlp memory */
1669 NLP_SET_FREE_REQ(ndlp);
1670 spin_unlock_irq(&phba->ndlp_lock);
1671
James Smart58da1ff2008-04-07 10:15:56 -04001672 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1673 ndlp->nlp_DID == Fabric_DID) {
1674 /* Just free up ndlp with Fabric_DID for vports */
1675 lpfc_nlp_put(ndlp);
1676 continue;
1677 }
1678
James Smart87af33f2007-10-27 13:37:43 -04001679 if (ndlp->nlp_type & NLP_FABRIC)
1680 lpfc_disc_state_machine(vport, ndlp, NULL,
1681 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001682
James Smart87af33f2007-10-27 13:37:43 -04001683 lpfc_disc_state_machine(vport, ndlp, NULL,
1684 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001685
James Smart87af33f2007-10-27 13:37:43 -04001686 }
1687
James Smarta8adb832007-10-27 13:37:53 -04001688 /* At this point, ALL ndlp's should be gone
1689 * because of the previous NLP_EVT_DEVICE_RM.
1690 * Lets wait for this to happen, if needed.
1691 */
James Smart87af33f2007-10-27 13:37:43 -04001692 while (!list_empty(&vport->fc_nodes)) {
1693
James Smarta8adb832007-10-27 13:37:53 -04001694 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001695 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001696 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001697 list_for_each_entry_safe(ndlp, next_ndlp,
1698 &vport->fc_nodes, nlp_listp) {
1699 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1700 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001701 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001702 "usgmap:x%x refcnt:%d\n",
1703 ndlp->nlp_DID, (void *)ndlp,
1704 ndlp->nlp_usg_map,
1705 atomic_read(
1706 &ndlp->kref.refcount));
1707 }
James Smarta8adb832007-10-27 13:37:53 -04001708 break;
James Smart87af33f2007-10-27 13:37:43 -04001709 }
James Smarta8adb832007-10-27 13:37:53 -04001710
1711 /* Wait for any activity on ndlps to settle */
1712 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001713 }
dea31012005-04-17 16:05:31 -05001714 return;
1715}
1716
James Smarte59058c2008-08-24 21:49:00 -04001717/**
1718 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1719 * @vport: pointer to a virtual N_Port data structure.
1720 *
1721 * This routine stops all the timers associated with a @vport. This function
1722 * is invoked before disabling or deleting a @vport. Note that the physical
1723 * port is treated as @vport 0.
1724 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001725void
1726lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001727{
James Smart92d7f7b2007-06-17 19:56:38 -05001728 del_timer_sync(&vport->els_tmofunc);
1729 del_timer_sync(&vport->fc_fdmitmo);
1730 lpfc_can_disctmo(vport);
1731 return;
dea31012005-04-17 16:05:31 -05001732}
1733
James Smarte59058c2008-08-24 21:49:00 -04001734/**
1735 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1736 * @phba: pointer to lpfc hba data structure.
1737 *
1738 * This routine stops all the timers associated with a HBA. This function is
1739 * invoked before either putting a HBA offline or unloading the driver.
1740 **/
James Smart2e0fef82007-06-17 19:56:36 -05001741static void
James Smart92d7f7b2007-06-17 19:56:38 -05001742lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001743{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001744 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001745 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001746 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001747 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001748 phba->hb_outstanding = 0;
1749 del_timer_sync(&phba->hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001750 del_timer_sync(&phba->eratt_poll);
James Smart2e0fef82007-06-17 19:56:36 -05001751 return;
dea31012005-04-17 16:05:31 -05001752}
1753
James Smarte59058c2008-08-24 21:49:00 -04001754/**
1755 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1756 * @phba: pointer to lpfc hba data structure.
1757 *
1758 * This routine marks a HBA's management interface as blocked. Once the HBA's
1759 * management interface is marked as blocked, all the user space access to
1760 * the HBA, whether they are from sysfs interface or libdfc interface will
1761 * all be blocked. The HBA is set to block the management interface when the
1762 * driver prepares the HBA interface for online or offline.
1763 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001764static void
1765lpfc_block_mgmt_io(struct lpfc_hba * phba)
1766{
1767 unsigned long iflag;
1768
1769 spin_lock_irqsave(&phba->hbalock, iflag);
1770 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1771 spin_unlock_irqrestore(&phba->hbalock, iflag);
1772}
1773
James Smarte59058c2008-08-24 21:49:00 -04001774/**
1775 * lpfc_online: Initialize and bring a HBA online.
1776 * @phba: pointer to lpfc hba data structure.
1777 *
1778 * This routine initializes the HBA and brings a HBA online. During this
1779 * process, the management interface is blocked to prevent user space access
1780 * to the HBA interfering with the driver initialization.
1781 *
1782 * Return codes
1783 * 0 - successful
1784 * 1 - failed
1785 **/
dea31012005-04-17 16:05:31 -05001786int
James Smart2e0fef82007-06-17 19:56:36 -05001787lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001788{
James Smart2e0fef82007-06-17 19:56:36 -05001789 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001790 struct lpfc_vport **vports;
1791 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001792
dea31012005-04-17 16:05:31 -05001793 if (!phba)
1794 return 0;
1795
James Smart2e0fef82007-06-17 19:56:36 -05001796 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001797 return 0;
1798
James Smarted957682007-06-17 19:56:37 -05001799 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001800 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001801
James Smart46fa3112007-04-25 09:51:45 -04001802 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001803
James Smart46fa3112007-04-25 09:51:45 -04001804 if (!lpfc_sli_queue_setup(phba)) {
1805 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001806 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001807 }
1808
1809 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1810 lpfc_unblock_mgmt_io(phba);
1811 return 1;
1812 }
dea31012005-04-17 16:05:31 -05001813
James Smart549e55c2007-08-02 11:09:51 -04001814 vports = lpfc_create_vport_work_array(phba);
1815 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001816 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001817 struct Scsi_Host *shost;
1818 shost = lpfc_shost_from_vport(vports[i]);
1819 spin_lock_irq(shost->host_lock);
1820 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1821 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1822 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1823 spin_unlock_irq(shost->host_lock);
1824 }
James Smart09372822008-01-11 01:52:54 -05001825 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001826
James Smart46fa3112007-04-25 09:51:45 -04001827 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001828 return 0;
1829}
1830
James Smarte59058c2008-08-24 21:49:00 -04001831/**
1832 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1833 * @phba: pointer to lpfc hba data structure.
1834 *
1835 * This routine marks a HBA's management interface as not blocked. Once the
1836 * HBA's management interface is marked as not blocked, all the user space
1837 * access to the HBA, whether they are from sysfs interface or libdfc
1838 * interface will be allowed. The HBA is set to block the management interface
1839 * when the driver prepares the HBA interface for online or offline and then
1840 * set to unblock the management interface afterwards.
1841 **/
James Smart46fa3112007-04-25 09:51:45 -04001842void
James Smart46fa3112007-04-25 09:51:45 -04001843lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1844{
1845 unsigned long iflag;
1846
James Smart2e0fef82007-06-17 19:56:36 -05001847 spin_lock_irqsave(&phba->hbalock, iflag);
1848 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1849 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001850}
1851
James Smarte59058c2008-08-24 21:49:00 -04001852/**
1853 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1854 * @phba: pointer to lpfc hba data structure.
1855 *
1856 * This routine is invoked to prepare a HBA to be brought offline. It performs
1857 * unregistration login to all the nodes on all vports and flushes the mailbox
1858 * queue to make it ready to be brought offline.
1859 **/
James Smart46fa3112007-04-25 09:51:45 -04001860void
1861lpfc_offline_prep(struct lpfc_hba * phba)
1862{
James Smart2e0fef82007-06-17 19:56:36 -05001863 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001864 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001865 struct lpfc_vport **vports;
1866 int i;
dea31012005-04-17 16:05:31 -05001867
James Smart2e0fef82007-06-17 19:56:36 -05001868 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001869 return;
dea31012005-04-17 16:05:31 -05001870
James Smart46fa3112007-04-25 09:51:45 -04001871 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001872
1873 lpfc_linkdown(phba);
1874
James Smart87af33f2007-10-27 13:37:43 -04001875 /* Issue an unreg_login to all nodes on all vports */
1876 vports = lpfc_create_vport_work_array(phba);
1877 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001878 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001879 struct Scsi_Host *shost;
1880
James Smarta8adb832007-10-27 13:37:53 -04001881 if (vports[i]->load_flag & FC_UNLOADING)
1882 continue;
James Smart87af33f2007-10-27 13:37:43 -04001883 shost = lpfc_shost_from_vport(vports[i]);
1884 list_for_each_entry_safe(ndlp, next_ndlp,
1885 &vports[i]->fc_nodes,
1886 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001887 if (!NLP_CHK_NODE_ACT(ndlp))
1888 continue;
James Smart87af33f2007-10-27 13:37:43 -04001889 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1890 continue;
1891 if (ndlp->nlp_type & NLP_FABRIC) {
1892 lpfc_disc_state_machine(vports[i], ndlp,
1893 NULL, NLP_EVT_DEVICE_RECOVERY);
1894 lpfc_disc_state_machine(vports[i], ndlp,
1895 NULL, NLP_EVT_DEVICE_RM);
1896 }
1897 spin_lock_irq(shost->host_lock);
1898 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1899 spin_unlock_irq(shost->host_lock);
1900 lpfc_unreg_rpi(vports[i], ndlp);
1901 }
1902 }
1903 }
James Smart09372822008-01-11 01:52:54 -05001904 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001905
James Smart46fa3112007-04-25 09:51:45 -04001906 lpfc_sli_flush_mbox_queue(phba);
1907}
1908
James Smarte59058c2008-08-24 21:49:00 -04001909/**
1910 * lpfc_offline: Bring a HBA offline.
1911 * @phba: pointer to lpfc hba data structure.
1912 *
1913 * This routine actually brings a HBA offline. It stops all the timers
1914 * associated with the HBA, brings down the SLI layer, and eventually
1915 * marks the HBA as in offline state for the upper layer protocol.
1916 **/
James Smart46fa3112007-04-25 09:51:45 -04001917void
James Smart2e0fef82007-06-17 19:56:36 -05001918lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001919{
James Smart549e55c2007-08-02 11:09:51 -04001920 struct Scsi_Host *shost;
1921 struct lpfc_vport **vports;
1922 int i;
James Smart46fa3112007-04-25 09:51:45 -04001923
James Smart549e55c2007-08-02 11:09:51 -04001924 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001925 return;
James Smart688a8862006-07-06 15:49:56 -04001926
dea31012005-04-17 16:05:31 -05001927 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001928 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001929 vports = lpfc_create_vport_work_array(phba);
1930 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001931 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001932 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001933 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001934 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001935 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001936 /* Bring down the SLI Layer and cleanup. The HBA is offline
1937 now. */
1938 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001939 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001940 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001941 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001942 vports = lpfc_create_vport_work_array(phba);
1943 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001944 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001945 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001946 spin_lock_irq(shost->host_lock);
1947 vports[i]->work_port_events = 0;
1948 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1949 spin_unlock_irq(shost->host_lock);
1950 }
James Smart09372822008-01-11 01:52:54 -05001951 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001952}
1953
James Smarte59058c2008-08-24 21:49:00 -04001954/**
1955 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1956 * @phba: pointer to lpfc hba data structure.
1957 *
1958 * This routine is to free all the SCSI buffers and IOCBs from the driver
1959 * list back to kernel. It is called from lpfc_pci_remove_one to free
1960 * the internal resources before the device is removed from the system.
1961 *
1962 * Return codes
1963 * 0 - successful (for now, it always returns 0)
1964 **/
dea31012005-04-17 16:05:31 -05001965static int
James Smart2e0fef82007-06-17 19:56:36 -05001966lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001967{
1968 struct lpfc_scsi_buf *sb, *sb_next;
1969 struct lpfc_iocbq *io, *io_next;
1970
James Smart2e0fef82007-06-17 19:56:36 -05001971 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001972 /* Release all the lpfc_scsi_bufs maintained by this host. */
1973 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1974 list_del(&sb->list);
1975 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001976 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001977 kfree(sb);
1978 phba->total_scsi_bufs--;
1979 }
1980
1981 /* Release all the lpfc_iocbq entries maintained by this host. */
1982 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1983 list_del(&io->list);
1984 kfree(io);
1985 phba->total_iocbq_bufs--;
1986 }
1987
James Smart2e0fef82007-06-17 19:56:36 -05001988 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001989
1990 return 0;
1991}
1992
James Smarte59058c2008-08-24 21:49:00 -04001993/**
1994 * lpfc_create_port: Create an FC port.
1995 * @phba: pointer to lpfc hba data structure.
1996 * @instance: a unique integer ID to this FC port.
1997 * @dev: pointer to the device data structure.
1998 *
1999 * This routine creates a FC port for the upper layer protocol. The FC port
2000 * can be created on top of either a physical port or a virtual port provided
2001 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2002 * and associates the FC port created before adding the shost into the SCSI
2003 * layer.
2004 *
2005 * Return codes
2006 * @vport - pointer to the virtual N_Port data structure.
2007 * NULL - port create failed.
2008 **/
James Smart2e0fef82007-06-17 19:56:36 -05002009struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002010lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002011{
James Smart2e0fef82007-06-17 19:56:36 -05002012 struct lpfc_vport *vport;
2013 struct Scsi_Host *shost;
2014 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002015
James Smart3de2a652007-08-02 11:09:59 -04002016 if (dev != &phba->pcidev->dev)
2017 shost = scsi_host_alloc(&lpfc_vport_template,
2018 sizeof(struct lpfc_vport));
2019 else
2020 shost = scsi_host_alloc(&lpfc_template,
2021 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002022 if (!shost)
2023 goto out;
James Smart47a86172007-04-25 09:53:22 -04002024
James Smart2e0fef82007-06-17 19:56:36 -05002025 vport = (struct lpfc_vport *) shost->hostdata;
2026 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002027 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002028 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002029 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002030
James Smart3de2a652007-08-02 11:09:59 -04002031 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002032 shost->unique_id = instance;
2033 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002034 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002035 shost->this_id = -1;
2036 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04002037 /*
James Smart2e0fef82007-06-17 19:56:36 -05002038 * Set initial can_queue value since 0 is no longer supported and
2039 * scsi_add_host will fail. This will be adjusted later based on the
2040 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002041 */
James Smart2e0fef82007-06-17 19:56:36 -05002042 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002043 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002044 shost->transportt = lpfc_vport_transport_template;
2045 vport->port_type = LPFC_NPIV_PORT;
2046 } else {
2047 shost->transportt = lpfc_transport_template;
2048 vport->port_type = LPFC_PHYSICAL_PORT;
2049 }
James Smart47a86172007-04-25 09:53:22 -04002050
James Smart2e0fef82007-06-17 19:56:36 -05002051 /* Initialize all internally managed lists. */
2052 INIT_LIST_HEAD(&vport->fc_nodes);
2053 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002054
James Smart2e0fef82007-06-17 19:56:36 -05002055 init_timer(&vport->fc_disctmo);
2056 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002057 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002058
James Smart2e0fef82007-06-17 19:56:36 -05002059 init_timer(&vport->fc_fdmitmo);
2060 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002061 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002062
James Smart2e0fef82007-06-17 19:56:36 -05002063 init_timer(&vport->els_tmofunc);
2064 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002065 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002066
James Smart3de2a652007-08-02 11:09:59 -04002067 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05002068 if (error)
2069 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002070
James Smart549e55c2007-08-02 11:09:51 -04002071 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002072 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002073 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002074 return vport;
James Smart47a86172007-04-25 09:53:22 -04002075
James Smart2e0fef82007-06-17 19:56:36 -05002076out_put_shost:
2077 scsi_host_put(shost);
2078out:
2079 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002080}
2081
James Smarte59058c2008-08-24 21:49:00 -04002082/**
2083 * destroy_port: Destroy an FC port.
2084 * @vport: pointer to an lpfc virtual N_Port data structure.
2085 *
2086 * This routine destroys a FC port from the upper layer protocol. All the
2087 * resources associated with the port are released.
2088 **/
James Smart2e0fef82007-06-17 19:56:36 -05002089void
2090destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002091{
James Smart92d7f7b2007-06-17 19:56:38 -05002092 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2093 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002094
James Smart858c9f62007-06-17 19:56:39 -05002095 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002096 fc_remove_host(shost);
2097 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002098
James Smart92d7f7b2007-06-17 19:56:38 -05002099 spin_lock_irq(&phba->hbalock);
2100 list_del_init(&vport->listentry);
2101 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002102
James Smart92d7f7b2007-06-17 19:56:38 -05002103 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002104 return;
James Smart47a86172007-04-25 09:53:22 -04002105}
2106
James Smarte59058c2008-08-24 21:49:00 -04002107/**
2108 * lpfc_get_instance: Get a unique integer ID.
2109 *
2110 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2111 * uses the kernel idr facility to perform the task.
2112 *
2113 * Return codes:
2114 * instance - a unique integer ID allocated as the new instance.
2115 * -1 - lpfc get instance failed.
2116 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002117int
2118lpfc_get_instance(void)
2119{
2120 int instance = 0;
2121
2122 /* Assign an unused number */
2123 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2124 return -1;
2125 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2126 return -1;
2127 return instance;
2128}
2129
James Smarte59058c2008-08-24 21:49:00 -04002130/**
2131 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2132 * @shost: pointer to SCSI host data structure.
2133 * @time: elapsed time of the scan in jiffies.
2134 *
2135 * This routine is called by the SCSI layer with a SCSI host to determine
2136 * whether the scan host is finished.
2137 *
2138 * Note: there is no scan_start function as adapter initialization will have
2139 * asynchronously kicked off the link initialization.
2140 *
2141 * Return codes
2142 * 0 - SCSI host scan is not over yet.
2143 * 1 - SCSI host scan is over.
2144 **/
James Smart47a86172007-04-25 09:53:22 -04002145int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2146{
James Smart2e0fef82007-06-17 19:56:36 -05002147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2148 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002149 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002150
James Smart858c9f62007-06-17 19:56:39 -05002151 spin_lock_irq(shost->host_lock);
2152
James Smart51ef4c22007-08-02 11:10:31 -04002153 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002154 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002155 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002156 }
James Smart2e0fef82007-06-17 19:56:36 -05002157 if (time >= 30 * HZ) {
2158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002159 "0461 Scanning longer than 30 "
2160 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002161 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002162 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002163 }
2164 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2165 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002166 "0465 Link down longer than 15 "
2167 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002168 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002169 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002170 }
2171
James Smart2e0fef82007-06-17 19:56:36 -05002172 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002173 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002174 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002175 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002176 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002177 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002178 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002179 goto finished;
2180
2181 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002182
2183finished:
James Smart858c9f62007-06-17 19:56:39 -05002184 spin_unlock_irq(shost->host_lock);
2185 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002186}
2187
James Smarte59058c2008-08-24 21:49:00 -04002188/**
2189 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2190 * @shost: pointer to SCSI host data structure.
2191 *
2192 * This routine initializes a given SCSI host attributes on a FC port. The
2193 * SCSI host can be either on top of a physical port or a virtual port.
2194 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002195void lpfc_host_attrib_init(struct Scsi_Host *shost)
2196{
2197 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2198 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002199 /*
James Smart2e0fef82007-06-17 19:56:36 -05002200 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002201 */
2202
James Smart2e0fef82007-06-17 19:56:36 -05002203 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2204 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002205 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2206
2207 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002208 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002209 fc_host_supported_fc4s(shost)[2] = 1;
2210 fc_host_supported_fc4s(shost)[7] = 1;
2211
James Smart92d7f7b2007-06-17 19:56:38 -05002212 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2213 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002214
2215 fc_host_supported_speeds(shost) = 0;
2216 if (phba->lmt & LMT_10Gb)
2217 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002218 if (phba->lmt & LMT_8Gb)
2219 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002220 if (phba->lmt & LMT_4Gb)
2221 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2222 if (phba->lmt & LMT_2Gb)
2223 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2224 if (phba->lmt & LMT_1Gb)
2225 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2226
2227 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002228 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2229 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002230
2231 /* This value is also unchanging */
2232 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002233 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002234 fc_host_active_fc4s(shost)[2] = 1;
2235 fc_host_active_fc4s(shost)[7] = 1;
2236
James Smart92d7f7b2007-06-17 19:56:38 -05002237 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002238 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002239 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002240 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002241}
dea31012005-04-17 16:05:31 -05002242
James Smarte59058c2008-08-24 21:49:00 -04002243/**
2244 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2245 * @phba: pointer to lpfc hba data structure.
2246 *
2247 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2248 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2249 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2250 * on the current availability of PCI vector resources. The device driver is
2251 * responsible for calling the individual request_irq() to register each MSI-X
2252 * vector with a interrupt handler, which is done in this function. Note that
2253 * later when device is unloading, the driver should always call free_irq()
2254 * on all MSI-X vectors it has done request_irq() on before calling
2255 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2256 * will be left with MSI-X enabled and leaks its vectors.
2257 *
2258 * Return codes
2259 * 0 - sucessful
2260 * other values - error
2261 **/
James Smartdb2378e2008-02-08 18:49:51 -05002262static int
2263lpfc_enable_msix(struct lpfc_hba *phba)
2264{
James Smart93996272008-08-24 21:50:30 -04002265 int rc, i;
2266 LPFC_MBOXQ_t *pmb;
James Smartdb2378e2008-02-08 18:49:51 -05002267
James Smart93996272008-08-24 21:50:30 -04002268 /* Set up MSI-X multi-message vectors */
2269 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2270 phba->msix_entries[i].entry = i;
James Smartdb2378e2008-02-08 18:49:51 -05002271
James Smart93996272008-08-24 21:50:30 -04002272 /* Configure MSI-X capability structure */
2273 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
James Smartdb2378e2008-02-08 18:49:51 -05002274 ARRAY_SIZE(phba->msix_entries));
James Smart93996272008-08-24 21:50:30 -04002275 if (rc) {
James Smartdb2378e2008-02-08 18:49:51 -05002276 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05002277 "0420 PCI enable MSI-X failed (%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002278 goto msi_fail_out;
2279 } else
2280 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2281 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2282 "0477 MSI-X entry[%d]: vector=x%x "
2283 "message=%d\n", i,
2284 phba->msix_entries[i].vector,
2285 phba->msix_entries[i].entry);
2286 /*
2287 * Assign MSI-X vectors to interrupt handlers
2288 */
2289
2290 /* vector-0 is associated to slow-path handler */
2291 rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler,
2292 IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba);
2293 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002294 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002295 "0421 MSI-X slow-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002296 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002297 goto msi_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002298 }
2299
James Smart93996272008-08-24 21:50:30 -04002300 /* vector-1 is associated to fast-path handler */
2301 rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler,
2302 IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba);
2303
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 "0429 MSI-X fast-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002307 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002308 goto irq_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002309 }
James Smart93996272008-08-24 21:50:30 -04002310
2311 /*
2312 * Configure HBA MSI-X attention conditions to messages
2313 */
2314 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2315
2316 if (!pmb) {
2317 rc = -ENOMEM;
2318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2319 "0474 Unable to allocate memory for issuing "
2320 "MBOX_CONFIG_MSI command\n");
2321 goto mem_fail_out;
2322 }
2323 rc = lpfc_config_msi(phba, pmb);
2324 if (rc)
2325 goto mbx_fail_out;
2326 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2327 if (rc != MBX_SUCCESS) {
James Smart5b75da22008-12-04 22:39:35 -05002328 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smart93996272008-08-24 21:50:30 -04002329 "0351 Config MSI mailbox command failed, "
2330 "mbxCmd x%x, mbxStatus x%x\n",
2331 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
2332 goto mbx_fail_out;
2333 }
2334
2335 /* Free memory allocated for mailbox command */
2336 mempool_free(pmb, phba->mbox_mem_pool);
2337 return rc;
2338
2339mbx_fail_out:
2340 /* Free memory allocated for mailbox command */
2341 mempool_free(pmb, phba->mbox_mem_pool);
2342
2343mem_fail_out:
2344 /* free the irq already requested */
2345 free_irq(phba->msix_entries[1].vector, phba);
2346
2347irq_fail_out:
2348 /* free the irq already requested */
2349 free_irq(phba->msix_entries[0].vector, phba);
2350
2351msi_fail_out:
2352 /* Unconfigure MSI-X capability structure */
2353 pci_disable_msix(phba->pcidev);
2354 return rc;
James Smartdb2378e2008-02-08 18:49:51 -05002355}
2356
James Smarte59058c2008-08-24 21:49:00 -04002357/**
2358 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2359 * @phba: pointer to lpfc hba data structure.
2360 *
2361 * This routine is invoked to release the MSI-X vectors and then disable the
2362 * MSI-X interrupt mode.
2363 **/
James Smartdb2378e2008-02-08 18:49:51 -05002364static void
2365lpfc_disable_msix(struct lpfc_hba *phba)
2366{
James Smart93996272008-08-24 21:50:30 -04002367 int i;
2368
2369 /* Free up MSI-X multi-message vectors */
2370 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2371 free_irq(phba->msix_entries[i].vector, phba);
2372 /* Disable MSI-X */
James Smartdb2378e2008-02-08 18:49:51 -05002373 pci_disable_msix(phba->pcidev);
2374}
2375
James Smarte59058c2008-08-24 21:49:00 -04002376/**
James Smart5b75da22008-12-04 22:39:35 -05002377 * lpfc_enable_msi: Enable MSI interrupt mode.
2378 * @phba: pointer to lpfc hba data structure.
2379 *
2380 * This routine is invoked to enable the MSI interrupt mode. The kernel
2381 * function pci_enable_msi() is called to enable the MSI vector. The
2382 * device driver is responsible for calling the request_irq() to register
2383 * MSI vector with a interrupt the handler, which is done in this function.
2384 *
2385 * Return codes
2386 * 0 - sucessful
2387 * other values - error
2388 */
2389static int
2390lpfc_enable_msi(struct lpfc_hba *phba)
2391{
2392 int rc;
2393
2394 rc = pci_enable_msi(phba->pcidev);
2395 if (!rc)
2396 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2397 "0462 PCI enable MSI mode success.\n");
2398 else {
2399 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2400 "0471 PCI enable MSI mode failed (%d)\n", rc);
2401 return rc;
2402 }
2403
2404 rc = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2405 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2406 if (rc) {
2407 pci_disable_msi(phba->pcidev);
2408 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2409 "0478 MSI request_irq failed (%d)\n", rc);
2410 }
2411 return rc;
2412}
2413
2414/**
2415 * lpfc_disable_msi: Disable MSI interrupt mode.
2416 * @phba: pointer to lpfc hba data structure.
2417 *
2418 * This routine is invoked to disable the MSI interrupt mode. The driver
2419 * calls free_irq() on MSI vector it has done request_irq() on before
2420 * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and
2421 * a device will be left with MSI enabled and leaks its vector.
2422 */
2423
2424static void
2425lpfc_disable_msi(struct lpfc_hba *phba)
2426{
2427 free_irq(phba->pcidev->irq, phba);
2428 pci_disable_msi(phba->pcidev);
2429 return;
2430}
2431
2432/**
2433 * lpfc_log_intr_mode: Log the active interrupt mode
2434 * @phba: pointer to lpfc hba data structure.
2435 * @intr_mode: active interrupt mode adopted.
2436 *
2437 * This routine it invoked to log the currently used active interrupt mode
2438 * to the device.
2439 */
2440static void
2441lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
2442{
2443 switch (intr_mode) {
2444 case 0:
2445 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2446 "0470 Enable INTx interrupt mode.\n");
2447 break;
2448 case 1:
2449 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2450 "0481 Enabled MSI interrupt mode.\n");
2451 break;
2452 case 2:
2453 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2454 "0480 Enabled MSI-X interrupt mode.\n");
2455 break;
2456 default:
2457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2458 "0482 Illegal interrupt mode.\n");
2459 break;
2460 }
2461 return;
2462}
2463
2464static void
2465lpfc_stop_port(struct lpfc_hba *phba)
2466{
2467 /* Clear all interrupt enable conditions */
2468 writel(0, phba->HCregaddr);
2469 readl(phba->HCregaddr); /* flush */
2470 /* Clear all pending interrupts */
2471 writel(0xffffffff, phba->HAregaddr);
2472 readl(phba->HAregaddr); /* flush */
2473
2474 /* Reset some HBA SLI setup states */
2475 lpfc_stop_phba_timers(phba);
2476 phba->pport->work_port_events = 0;
2477
2478 return;
2479}
2480
2481/**
2482 * lpfc_enable_intr: Enable device interrupt.
2483 * @phba: pointer to lpfc hba data structure.
2484 *
2485 * This routine is invoked to enable device interrupt and associate driver's
2486 * interrupt handler(s) to interrupt vector(s). Depends on the interrupt
2487 * mode configured to the driver, the driver will try to fallback from the
2488 * configured interrupt mode to an interrupt mode which is supported by the
2489 * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ.
2490 *
2491 * Return codes
2492 * 0 - sucessful
2493 * other values - error
2494 **/
2495static uint32_t
2496lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
2497{
2498 uint32_t intr_mode = LPFC_INTR_ERROR;
2499 int retval;
2500
2501 if (cfg_mode == 2) {
2502 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
2503 retval = lpfc_sli_config_port(phba, 3);
2504 if (!retval) {
2505 /* Now, try to enable MSI-X interrupt mode */
2506 retval = lpfc_enable_msix(phba);
2507 if (!retval) {
2508 /* Indicate initialization to MSI-X mode */
2509 phba->intr_type = MSIX;
2510 intr_mode = 2;
2511 }
2512 }
2513 }
2514
2515 /* Fallback to MSI if MSI-X initialization failed */
2516 if (cfg_mode >= 1 && phba->intr_type == NONE) {
2517 retval = lpfc_enable_msi(phba);
2518 if (!retval) {
2519 /* Indicate initialization to MSI mode */
2520 phba->intr_type = MSI;
2521 intr_mode = 1;
2522 }
2523 }
2524
2525 /* Fallback to INTx if both MSI-X/MSI initalization failed */
2526 if (phba->intr_type == NONE) {
2527 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2528 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2529 if (!retval) {
2530 /* Indicate initialization to INTx mode */
2531 phba->intr_type = INTx;
2532 intr_mode = 0;
2533 }
2534 }
2535 return intr_mode;
2536}
2537
2538/**
2539 * lpfc_disable_intr: Disable device interrupt.
2540 * @phba: pointer to lpfc hba data structure.
2541 *
2542 * This routine is invoked to disable device interrupt and disassociate the
2543 * driver's interrupt handler(s) from interrupt vector(s). Depending on the
2544 * interrupt mode, the driver will release the interrupt vector(s) for the
2545 * message signaled interrupt.
2546 **/
2547static void
2548lpfc_disable_intr(struct lpfc_hba *phba)
2549{
2550 /* Disable the currently initialized interrupt mode */
2551 if (phba->intr_type == MSIX)
2552 lpfc_disable_msix(phba);
2553 else if (phba->intr_type == MSI)
2554 lpfc_disable_msi(phba);
2555 else if (phba->intr_type == INTx)
2556 free_irq(phba->pcidev->irq, phba);
2557
2558 /* Reset interrupt management states */
2559 phba->intr_type = NONE;
2560 phba->sli.slistat.sli_intr = 0;
2561
2562 return;
2563}
2564
2565/**
James Smarte59058c2008-08-24 21:49:00 -04002566 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2567 * @pdev: pointer to PCI device
2568 * @pid: pointer to PCI device identifier
2569 *
2570 * This routine is to be registered to the kernel's PCI subsystem. When an
2571 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2572 * PCI device-specific information of the device and driver to see if the
2573 * driver state that it can support this kind of device. If the match is
2574 * successful, the driver core invokes this routine. If this routine
2575 * determines it can claim the HBA, it does all the initialization that it
2576 * needs to do to handle the HBA properly.
2577 *
2578 * Return code
2579 * 0 - driver can claim the device
2580 * negative value - driver can not claim the device
2581 **/
dea31012005-04-17 16:05:31 -05002582static int __devinit
2583lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2584{
James Smart2e0fef82007-06-17 19:56:36 -05002585 struct lpfc_vport *vport = NULL;
2586 struct lpfc_hba *phba;
2587 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002588 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002589 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04002590 void *ptr;
dea31012005-04-17 16:05:31 -05002591 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04002592 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04002593 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05002594 uint16_t iotag;
James Smart5b75da22008-12-04 22:39:35 -05002595 uint32_t cfg_mode, intr_mode;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002596 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
James Smartea2151b2008-09-07 11:52:10 -04002597 struct lpfc_adapter_event_header adapter_event;
dea31012005-04-17 16:05:31 -05002598
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01002599 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05002600 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002601 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05002602 goto out_disable_device;
2603
James Smart2e0fef82007-06-17 19:56:36 -05002604 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2605 if (!phba)
dea31012005-04-17 16:05:31 -05002606 goto out_release_regions;
2607
James Smartea2151b2008-09-07 11:52:10 -04002608 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002609 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002610
James Smarte47c9092008-02-08 18:49:26 -05002611 /* Initialize ndlp management spinlock */
2612 spin_lock_init(&phba->ndlp_lock);
2613
dea31012005-04-17 16:05:31 -05002614 phba->pcidev = pdev;
2615
2616 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05002617 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05002618 goto out_free_phba;
dea31012005-04-17 16:05:31 -05002619
James Smart2e0fef82007-06-17 19:56:36 -05002620 INIT_LIST_HEAD(&phba->port_list);
James Smart84774a42008-08-24 21:50:06 -04002621 init_waitqueue_head(&phba->wait_4_mlo_m_q);
James Smart2e0fef82007-06-17 19:56:36 -05002622 /*
2623 * Get all the module params for configuring this host and then
2624 * establish the host.
2625 */
2626 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002627 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002628
2629 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05002630 init_timer(&phba->hb_tmofunc);
2631 phba->hb_tmofunc.function = lpfc_hb_timeout;
2632 phba->hb_tmofunc.data = (unsigned long)phba;
2633
dea31012005-04-17 16:05:31 -05002634 psli = &phba->sli;
2635 init_timer(&psli->mbox_tmo);
2636 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002637 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002638 init_timer(&phba->fcp_poll_timer);
2639 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002640 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002641 init_timer(&phba->fabric_block_timer);
2642 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2643 phba->fabric_block_timer.data = (unsigned long) phba;
James Smart93996272008-08-24 21:50:30 -04002644 init_timer(&phba->eratt_poll);
2645 phba->eratt_poll.function = lpfc_poll_eratt;
2646 phba->eratt_poll.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002647
dea31012005-04-17 16:05:31 -05002648 pci_set_master(pdev);
James Smart97207482008-12-04 22:39:19 -05002649 pci_save_state(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002650 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002651
2652 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2653 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2654 goto out_idr_remove;
2655
2656 /*
2657 * Get the bus address of Bar0 and Bar2 and the number of bytes
2658 * required by each mapping.
2659 */
2660 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2661 bar0map_len = pci_resource_len(phba->pcidev, 0);
2662
2663 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2664 bar2map_len = pci_resource_len(phba->pcidev, 2);
2665
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002666 /* Map HBA SLIM to a kernel virtual address. */
James Smart93996272008-08-24 21:50:30 -04002667 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002668 if (!phba->slim_memmap_p) {
2669 error = -ENODEV;
2670 dev_printk(KERN_ERR, &pdev->dev,
2671 "ioremap failed for SLIM memory.\n");
2672 goto out_idr_remove;
2673 }
2674
2675 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002676 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002677 if (!phba->ctrl_regs_memmap_p) {
2678 error = -ENODEV;
2679 dev_printk(KERN_ERR, &pdev->dev,
2680 "ioremap failed for HBA control registers.\n");
2681 goto out_iounmap_slim;
2682 }
dea31012005-04-17 16:05:31 -05002683
2684 /* Allocate memory for SLI-2 structures */
James Smart34b02dc2008-08-24 21:49:55 -04002685 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2686 SLI2_SLIM_SIZE,
2687 &phba->slim2p.phys,
2688 GFP_KERNEL);
2689 if (!phba->slim2p.virt)
dea31012005-04-17 16:05:31 -05002690 goto out_iounmap;
2691
James Smart34b02dc2008-08-24 21:49:55 -04002692 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
James Smartd7c255b2008-08-24 21:50:00 -04002693 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
2694 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
2695 phba->IOCBs = (phba->slim2p.virt +
2696 offsetof(struct lpfc_sli2_slim, IOCBs));
dea31012005-04-17 16:05:31 -05002697
James Smarted957682007-06-17 19:56:37 -05002698 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2699 lpfc_sli_hbq_size(),
2700 &phba->hbqslimp.phys,
2701 GFP_KERNEL);
2702 if (!phba->hbqslimp.virt)
2703 goto out_free_slim;
2704
James Smart51ef4c22007-08-02 11:10:31 -04002705 hbq_count = lpfc_sli_hbq_count();
2706 ptr = phba->hbqslimp.virt;
2707 for (i = 0; i < hbq_count; ++i) {
2708 phba->hbqs[i].hbq_virt = ptr;
2709 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2710 ptr += (lpfc_hbq_defs[i]->entry_count *
2711 sizeof(struct lpfc_hbq_entry));
2712 }
2713 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2714 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2715
James Smarted957682007-06-17 19:56:37 -05002716 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2717
James Smart3163f722008-02-08 18:50:25 -05002718 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2719
dea31012005-04-17 16:05:31 -05002720 /* Initialize the SLI Layer to run with lpfc HBAs. */
2721 lpfc_sli_setup(phba);
2722 lpfc_sli_queue_setup(phba);
2723
James Smart98c9ea52007-10-27 13:37:33 -04002724 retval = lpfc_mem_alloc(phba);
2725 if (retval) {
2726 error = retval;
James Smarted957682007-06-17 19:56:37 -05002727 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002728 }
dea31012005-04-17 16:05:31 -05002729
2730 /* Initialize and populate the iocb list per host. */
2731 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2732 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002733 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002734 if (iocbq_entry == NULL) {
2735 printk(KERN_ERR "%s: only allocated %d iocbs of "
2736 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002737 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002738 error = -ENOMEM;
2739 goto out_free_iocbq;
2740 }
2741
James Bottomley604a3e32005-10-29 10:28:33 -05002742 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2743 if (iotag == 0) {
2744 kfree (iocbq_entry);
2745 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2746 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002747 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002748 error = -ENOMEM;
2749 goto out_free_iocbq;
2750 }
James Smart2e0fef82007-06-17 19:56:36 -05002751
2752 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002753 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2754 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002755 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002756 }
2757
2758 /* Initialize HBA structure */
2759 phba->fc_edtov = FF_DEF_EDTOV;
2760 phba->fc_ratov = FF_DEF_RATOV;
2761 phba->fc_altov = FF_DEF_ALTOV;
2762 phba->fc_arbtov = FF_DEF_ARBTOV;
2763
2764 INIT_LIST_HEAD(&phba->work_list);
James Smart93996272008-08-24 21:50:30 -04002765 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
dea31012005-04-17 16:05:31 -05002766 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2767
James Smart5e9d9b82008-06-14 22:52:53 -04002768 /* Initialize the wait queue head for the kernel thread */
2769 init_waitqueue_head(&phba->work_waitq);
2770
dea31012005-04-17 16:05:31 -05002771 /* Startup the kernel thread for this host adapter. */
2772 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2773 "lpfc_worker_%d", phba->brd_no);
2774 if (IS_ERR(phba->worker_thread)) {
2775 error = PTR_ERR(phba->worker_thread);
2776 goto out_free_iocbq;
2777 }
2778
dea31012005-04-17 16:05:31 -05002779 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002780 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002781 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2782
James Smart92d7f7b2007-06-17 19:56:38 -05002783 /* Initialize list of fabric iocbs */
2784 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2785
James Smart0ff10d42008-01-11 01:52:36 -05002786 /* Initialize list to save ELS buffers */
2787 INIT_LIST_HEAD(&phba->elsbuf);
2788
James Smart3de2a652007-08-02 11:09:59 -04002789 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002790 if (!vport)
2791 goto out_kthread_stop;
2792
2793 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002794 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002795 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002796
James Smart92d7f7b2007-06-17 19:56:38 -05002797 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05002798
James Smart93996272008-08-24 21:50:30 -04002799 phba->MBslimaddr = phba->slim_memmap_p;
2800 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2801 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2802 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2803 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2804
James Smart5b75da22008-12-04 22:39:35 -05002805 /* Configure sysfs attributes */
James Smart98c9ea52007-10-27 13:37:33 -04002806 if (lpfc_alloc_sysfs_attr(vport)) {
James Smart93996272008-08-24 21:50:30 -04002807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2808 "1476 Failed to allocate sysfs attr\n");
James Smart98c9ea52007-10-27 13:37:33 -04002809 error = -ENOMEM;
James Smart5b75da22008-12-04 22:39:35 -05002810 goto out_destroy_port;
James Smart98c9ea52007-10-27 13:37:33 -04002811 }
dea31012005-04-17 16:05:31 -05002812
James Smart5b75da22008-12-04 22:39:35 -05002813 cfg_mode = phba->cfg_use_msi;
2814 while (true) {
2815 /* Configure and enable interrupt */
2816 intr_mode = lpfc_enable_intr(phba, cfg_mode);
2817 if (intr_mode == LPFC_INTR_ERROR) {
2818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2819 "0426 Failed to enable interrupt.\n");
2820 goto out_free_sysfs_attr;
2821 }
2822 /* HBA SLI setup */
2823 if (lpfc_sli_hba_setup(phba)) {
2824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2825 "1477 Failed to set up hba\n");
2826 error = -ENODEV;
2827 goto out_remove_device;
2828 }
2829
2830 /* Wait 50ms for the interrupts of previous mailbox commands */
2831 msleep(50);
2832 /* Check active interrupts received */
2833 if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
2834 /* Log the current active interrupt mode */
2835 phba->intr_mode = intr_mode;
2836 lpfc_log_intr_mode(phba, intr_mode);
2837 break;
2838 } else {
2839 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2840 "0451 Configure interrupt mode (%d) "
2841 "failed active interrupt test.\n",
2842 intr_mode);
2843 if (intr_mode == 0) {
2844 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2845 "0479 Failed to enable "
2846 "interrupt.\n");
2847 error = -ENODEV;
2848 goto out_remove_device;
2849 }
2850 /* Stop HBA SLI setups */
2851 lpfc_stop_port(phba);
2852 /* Disable the current interrupt mode */
2853 lpfc_disable_intr(phba);
2854 /* Try next level of interrupt mode */
2855 cfg_mode = --intr_mode;
2856 }
James Smart98c9ea52007-10-27 13:37:33 -04002857 }
James Smart858c9f62007-06-17 19:56:39 -05002858
2859 /*
2860 * hba setup may have changed the hba_queue_depth so we need to adjust
2861 * the value of can_queue.
2862 */
2863 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2864
2865 lpfc_host_attrib_init(shost);
2866
James Smart2e0fef82007-06-17 19:56:36 -05002867 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2868 spin_lock_irq(shost->host_lock);
2869 lpfc_poll_start_timer(phba);
2870 spin_unlock_irq(shost->host_lock);
2871 }
James Smart8f6d98d2006-08-01 07:34:00 -04002872
James Smart93996272008-08-24 21:50:30 -04002873 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2874 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04002875 /* Send board arrival event to upper layer */
2876 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
2877 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
2878 fc_host_post_vendor_event(shost, fc_get_event_number(),
2879 sizeof(adapter_event),
2880 (char *) &adapter_event,
James Smartddcc50f2008-12-04 22:38:46 -05002881 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04002882
dea31012005-04-17 16:05:31 -05002883 return 0;
2884
James Smart858c9f62007-06-17 19:56:39 -05002885out_remove_device:
James Smart858c9f62007-06-17 19:56:39 -05002886 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002887 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002888 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002889 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002890 phba->pport->work_port_events = 0;
James Smart5b75da22008-12-04 22:39:35 -05002891 lpfc_disable_intr(phba);
2892out_free_sysfs_attr:
2893 lpfc_free_sysfs_attr(vport);
2894out_destroy_port:
James Smart2e0fef82007-06-17 19:56:36 -05002895 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002896out_kthread_stop:
2897 kthread_stop(phba->worker_thread);
2898out_free_iocbq:
2899 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2900 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002901 kfree(iocbq_entry);
2902 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002903 }
2904 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002905out_free_hbqslimp:
James Smart34b02dc2008-08-24 21:49:55 -04002906 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2907 phba->hbqslimp.virt, phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002908out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04002909 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2910 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05002911out_iounmap:
2912 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002913out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002914 iounmap(phba->slim_memmap_p);
2915out_idr_remove:
2916 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002917out_free_phba:
2918 kfree(phba);
dea31012005-04-17 16:05:31 -05002919out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002920 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002921out_disable_device:
2922 pci_disable_device(pdev);
2923out:
James Smartdefbcf12006-04-16 22:26:50 -04002924 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002925 if (shost)
2926 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002927 return error;
2928}
2929
James Smarte59058c2008-08-24 21:49:00 -04002930/**
2931 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2932 * @pdev: pointer to PCI device
2933 *
2934 * This routine is to be registered to the kernel's PCI subsystem. When an
James Smart3a55b532008-12-04 22:38:54 -05002935 * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup
James Smarte59058c2008-08-24 21:49:00 -04002936 * for the HBA device to be removed from the PCI subsystem properly.
2937 **/
dea31012005-04-17 16:05:31 -05002938static void __devexit
2939lpfc_pci_remove_one(struct pci_dev *pdev)
2940{
James Smart2e0fef82007-06-17 19:56:36 -05002941 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2942 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05002943 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05002944 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05002945 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002946 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2947
James Smart549e55c2007-08-02 11:09:51 -04002948 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002949 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002950 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002951
James Smart858c9f62007-06-17 19:56:39 -05002952 lpfc_free_sysfs_attr(vport);
2953
James Smart09372822008-01-11 01:52:54 -05002954 kthread_stop(phba->worker_thread);
2955
James Smarteada2722008-12-04 22:39:13 -05002956 /* Release all the vports against this physical port */
2957 vports = lpfc_create_vport_work_array(phba);
2958 if (vports != NULL)
2959 for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++)
2960 fc_vport_terminate(vports[i]->fc_vport);
2961 lpfc_destroy_vport_work_array(phba, vports);
2962
2963 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05002964 fc_remove_host(shost);
2965 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002966 lpfc_cleanup(vport);
2967
James Smart2e0fef82007-06-17 19:56:36 -05002968 /*
2969 * Bring down the SLI Layer. This step disable all interrupts,
2970 * clears the rings, discards all mailbox commands, and resets
2971 * the HBA.
2972 */
2973 lpfc_sli_hba_down(phba);
2974 lpfc_sli_brdrestart(phba);
2975
James Smart92d7f7b2007-06-17 19:56:38 -05002976 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002977 spin_lock_irq(&phba->hbalock);
2978 list_del_init(&vport->listentry);
2979 spin_unlock_irq(&phba->hbalock);
2980
James Smart858c9f62007-06-17 19:56:39 -05002981 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002982
James Smart5b75da22008-12-04 22:39:35 -05002983 /* Disable interrupt */
2984 lpfc_disable_intr(phba);
dea31012005-04-17 16:05:31 -05002985
2986 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002987 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002988
2989 /*
2990 * Call scsi_free before mem_free since scsi bufs are released to their
2991 * corresponding pools here.
2992 */
2993 lpfc_scsi_free(phba);
2994 lpfc_mem_free(phba);
2995
James Smart34b02dc2008-08-24 21:49:55 -04002996 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2997 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05002998
James Smart2e0fef82007-06-17 19:56:36 -05002999 /* Free resources associated with SLI2 interface */
3000 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04003001 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05003002
3003 /* unmap adapter SLIM and Control Registers */
3004 iounmap(phba->ctrl_regs_memmap_p);
3005 iounmap(phba->slim_memmap_p);
3006
3007 idr_remove(&lpfc_hba_index, phba->brd_no);
3008
3009 kfree(phba);
3010
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003011 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05003012 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05003013}
3014
Linas Vepstas8d63f372007-02-14 14:28:36 -06003015/**
James Smart3a55b532008-12-04 22:38:54 -05003016 * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management.
3017 * @pdev: pointer to PCI device
3018 * @msg: power management message
3019 *
3020 * This routine is to be registered to the kernel's PCI subsystem to support
3021 * system Power Management (PM). When PM invokes this method, it quiesces the
3022 * device by stopping the driver's worker thread for the device, turning off
3023 * device's interrupt and DMA, and bring the device offline. Note that as the
3024 * driver implements the minimum PM requirements to a power-aware driver's PM
3025 * support for suspend/resume -- all the possible PM messages (SUSPEND,
3026 * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND
3027 * and the driver will fully reinitialize its device during resume() method
3028 * call, the driver will set device to PCI_D3hot state in PCI config space
3029 * instead of setting it according to the @msg provided by the PM.
3030 *
3031 * Return code
3032 * 0 - driver suspended the device
3033 * Error otherwise
3034 **/
3035static int
3036lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
3037{
3038 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3039 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3040
3041 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3042 "0473 PCI device Power Management suspend.\n");
3043
3044 /* Bring down the device */
3045 lpfc_offline_prep(phba);
3046 lpfc_offline(phba);
3047 kthread_stop(phba->worker_thread);
3048
3049 /* Disable interrupt from device */
3050 lpfc_disable_intr(phba);
3051
3052 /* Save device state to PCI config space */
3053 pci_save_state(pdev);
3054 pci_set_power_state(pdev, PCI_D3hot);
3055
3056 return 0;
3057}
3058
3059/**
3060 * lpfc_pci_resume_one: lpfc PCI func to resume device for power management.
3061 * @pdev: pointer to PCI device
3062 *
3063 * This routine is to be registered to the kernel's PCI subsystem to support
3064 * system Power Management (PM). When PM invokes this method, it restores
3065 * the device's PCI config space state and fully reinitializes the device
3066 * and brings it online. Note that as the driver implements the minimum PM
3067 * requirements to a power-aware driver's PM for suspend/resume -- all
3068 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
3069 * method call will be treated as SUSPEND and the driver will fully
3070 * reinitialize its device during resume() method call, the device will be
3071 * set to PCI_D0 directly in PCI config space before restoring the state.
3072 *
3073 * Return code
3074 * 0 - driver suspended the device
3075 * Error otherwise
3076 **/
3077static int
3078lpfc_pci_resume_one(struct pci_dev *pdev)
3079{
3080 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3081 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05003082 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003083 int error;
3084
3085 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3086 "0452 PCI device Power Management resume.\n");
3087
3088 /* Restore device state from PCI config space */
3089 pci_set_power_state(pdev, PCI_D0);
3090 pci_restore_state(pdev);
3091 if (pdev->is_busmaster)
3092 pci_set_master(pdev);
3093
3094 /* Startup the kernel thread for this host adapter. */
3095 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3096 "lpfc_worker_%d", phba->brd_no);
3097 if (IS_ERR(phba->worker_thread)) {
3098 error = PTR_ERR(phba->worker_thread);
3099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3100 "0434 PM resume failed to start worker "
3101 "thread: error=x%x.\n", error);
3102 return error;
3103 }
3104
James Smart5b75da22008-12-04 22:39:35 -05003105 /* Configure and enable interrupt */
3106 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3107 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05003108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05003109 "0430 PM resume Failed to enable interrupt\n");
3110 return -EIO;
3111 } else
3112 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003113
3114 /* Restart HBA and bring it online */
3115 lpfc_sli_brdrestart(phba);
3116 lpfc_online(phba);
3117
James Smart5b75da22008-12-04 22:39:35 -05003118 /* Log the current active interrupt mode */
3119 lpfc_log_intr_mode(phba, phba->intr_mode);
3120
James Smart3a55b532008-12-04 22:38:54 -05003121 return 0;
3122}
3123
3124/**
James Smarte59058c2008-08-24 21:49:00 -04003125 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
3126 * @pdev: pointer to PCI device.
3127 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003128 *
James Smarte59058c2008-08-24 21:49:00 -04003129 * This routine is registered to the PCI subsystem for error handling. This
3130 * function is called by the PCI subsystem after a PCI bus error affecting
3131 * this device has been detected. When this function is invoked, it will
3132 * need to stop all the I/Os and interrupt(s) to the device. Once that is
3133 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
3134 * perform proper recovery as desired.
3135 *
3136 * Return codes
3137 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
3138 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
3139 **/
Linas Vepstas8d63f372007-02-14 14:28:36 -06003140static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
3141 pci_channel_state_t state)
3142{
James Smart51ef4c22007-08-02 11:10:31 -04003143 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3144 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003145 struct lpfc_sli *psli = &phba->sli;
3146 struct lpfc_sli_ring *pring;
3147
James Smarta8e497d2008-08-24 21:50:11 -04003148 if (state == pci_channel_io_perm_failure) {
3149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3150 "0472 PCI channel I/O permanent failure\n");
3151 /* Block all SCSI devices' I/Os on the host */
3152 lpfc_scsi_dev_block(phba);
3153 /* Clean up all driver's outstanding SCSI I/Os */
3154 lpfc_sli_flush_fcp_rings(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003155 return PCI_ERS_RESULT_DISCONNECT;
James Smarta8e497d2008-08-24 21:50:11 -04003156 }
Linas Vepstas5daa49e2007-03-08 16:19:11 -06003157
Linas Vepstas8d63f372007-02-14 14:28:36 -06003158 pci_disable_device(pdev);
3159 /*
3160 * There may be I/Os dropped by the firmware.
3161 * Error iocb (I/O) on txcmplq and let the SCSI layer
3162 * retry it after re-establishing link.
3163 */
3164 pring = &psli->ring[psli->fcp_ring];
3165 lpfc_sli_abort_iocb_ring(phba, pring);
3166
James Smart5b75da22008-12-04 22:39:35 -05003167 /* Disable interrupt */
3168 lpfc_disable_intr(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003169
Linas Vepstas8d63f372007-02-14 14:28:36 -06003170 /* Request a slot reset. */
3171 return PCI_ERS_RESULT_NEED_RESET;
3172}
3173
3174/**
James Smarte59058c2008-08-24 21:49:00 -04003175 * lpfc_io_slot_reset: Restart a PCI device from scratch.
3176 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003177 *
James Smarte59058c2008-08-24 21:49:00 -04003178 * This routine is registered to the PCI subsystem for error handling. This is
3179 * called after PCI bus has been reset to restart the PCI card from scratch,
3180 * as if from a cold-boot. During the PCI subsystem error recovery, after the
3181 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
3182 * proper error recovery and then call this routine before calling the .resume
3183 * method to recover the device. This function will initialize the HBA device,
3184 * enable the interrupt, but it will just put the HBA to offline state without
3185 * passing any I/O traffic.
3186 *
3187 * Return codes
3188 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
3189 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06003190 */
3191static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
3192{
James Smart51ef4c22007-08-02 11:10:31 -04003193 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3194 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003195 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05003196 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003197
3198 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003199 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06003200 printk(KERN_ERR "lpfc: Cannot re-enable "
3201 "PCI device after reset.\n");
3202 return PCI_ERS_RESULT_DISCONNECT;
3203 }
3204
James Smart97207482008-12-04 22:39:19 -05003205 pci_restore_state(pdev);
3206 if (pdev->is_busmaster)
3207 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003208
James Smart92d7f7b2007-06-17 19:56:38 -05003209 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003210 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05003211 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003212
James Smart5b75da22008-12-04 22:39:35 -05003213 /* Configure and enable interrupt */
3214 intr_mode = lpfc_enable_intr(phba, phba->intr_mode);
3215 if (intr_mode == LPFC_INTR_ERROR) {
3216 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3217 "0427 Cannot re-enable interrupt after "
3218 "slot reset.\n");
3219 return PCI_ERS_RESULT_DISCONNECT;
3220 } else
3221 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003222
3223 /* Take device offline; this will perform cleanup */
3224 lpfc_offline(phba);
3225 lpfc_sli_brdrestart(phba);
3226
James Smart5b75da22008-12-04 22:39:35 -05003227 /* Log the current active interrupt mode */
3228 lpfc_log_intr_mode(phba, phba->intr_mode);
3229
Linas Vepstas8d63f372007-02-14 14:28:36 -06003230 return PCI_ERS_RESULT_RECOVERED;
3231}
3232
3233/**
James Smarte59058c2008-08-24 21:49:00 -04003234 * lpfc_io_resume: Resume PCI I/O operation.
3235 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06003236 *
James Smarte59058c2008-08-24 21:49:00 -04003237 * This routine is registered to the PCI subsystem for error handling. It is
3238 * called when kernel error recovery tells the lpfc driver that it is ok to
3239 * resume normal PCI operation after PCI bus error recovery. After this call,
3240 * traffic can start to flow from this device again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06003241 */
3242static void lpfc_io_resume(struct pci_dev *pdev)
3243{
James Smart51ef4c22007-08-02 11:10:31 -04003244 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3245 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06003246
James Smart58da1ff2008-04-07 10:15:56 -04003247 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06003248}
3249
dea31012005-04-17 16:05:31 -05003250static struct pci_device_id lpfc_id_table[] = {
3251 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
3252 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04003253 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
3254 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003255 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
3256 PCI_ANY_ID, PCI_ANY_ID, },
3257 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
3258 PCI_ANY_ID, PCI_ANY_ID, },
3259 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
3260 PCI_ANY_ID, PCI_ANY_ID, },
3261 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
3262 PCI_ANY_ID, PCI_ANY_ID, },
3263 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
3264 PCI_ANY_ID, PCI_ANY_ID, },
3265 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
3266 PCI_ANY_ID, PCI_ANY_ID, },
3267 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
3268 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003269 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
3270 PCI_ANY_ID, PCI_ANY_ID, },
3271 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
3272 PCI_ANY_ID, PCI_ANY_ID, },
3273 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
3274 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003275 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
3276 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003277 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
3278 PCI_ANY_ID, PCI_ANY_ID, },
3279 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
3280 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003281 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
3282 PCI_ANY_ID, PCI_ANY_ID, },
3283 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
3284 PCI_ANY_ID, PCI_ANY_ID, },
3285 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
3286 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003287 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
3288 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003289 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
3290 PCI_ANY_ID, PCI_ANY_ID, },
3291 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
3292 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003293 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
3294 PCI_ANY_ID, PCI_ANY_ID, },
3295 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
3296 PCI_ANY_ID, PCI_ANY_ID, },
3297 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
3298 PCI_ANY_ID, PCI_ANY_ID, },
3299 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
3300 PCI_ANY_ID, PCI_ANY_ID, },
3301 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
3302 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05003303 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
3304 PCI_ANY_ID, PCI_ANY_ID, },
3305 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
3306 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04003307 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
3308 PCI_ANY_ID, PCI_ANY_ID, },
3309 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
3310 PCI_ANY_ID, PCI_ANY_ID, },
3311 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
3312 PCI_ANY_ID, PCI_ANY_ID, },
3313 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
3314 PCI_ANY_ID, PCI_ANY_ID, },
3315 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
3316 PCI_ANY_ID, PCI_ANY_ID, },
3317 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
3318 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04003319 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
3320 PCI_ANY_ID, PCI_ANY_ID, },
3321 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
3322 PCI_ANY_ID, PCI_ANY_ID, },
3323 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
3324 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05003325 { 0 }
3326};
3327
3328MODULE_DEVICE_TABLE(pci, lpfc_id_table);
3329
Linas Vepstas8d63f372007-02-14 14:28:36 -06003330static struct pci_error_handlers lpfc_err_handler = {
3331 .error_detected = lpfc_io_error_detected,
3332 .slot_reset = lpfc_io_slot_reset,
3333 .resume = lpfc_io_resume,
3334};
3335
dea31012005-04-17 16:05:31 -05003336static struct pci_driver lpfc_driver = {
3337 .name = LPFC_DRIVER_NAME,
3338 .id_table = lpfc_id_table,
3339 .probe = lpfc_pci_probe_one,
3340 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05003341 .suspend = lpfc_pci_suspend_one,
3342 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05003343 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05003344};
3345
James Smarte59058c2008-08-24 21:49:00 -04003346/**
3347 * lpfc_init: lpfc module initialization routine.
3348 *
3349 * This routine is to be invoked when the lpfc module is loaded into the
3350 * kernel. The special kernel macro module_init() is used to indicate the
3351 * role of this routine to the kernel as lpfc module entry point.
3352 *
3353 * Return codes
3354 * 0 - successful
3355 * -ENOMEM - FC attach transport failed
3356 * all others - failed
3357 */
dea31012005-04-17 16:05:31 -05003358static int __init
3359lpfc_init(void)
3360{
3361 int error = 0;
3362
3363 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003364 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05003365
James Smart7ee5d432007-10-27 13:37:17 -04003366 if (lpfc_enable_npiv) {
3367 lpfc_transport_functions.vport_create = lpfc_vport_create;
3368 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
3369 }
dea31012005-04-17 16:05:31 -05003370 lpfc_transport_template =
3371 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04003372 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05003373 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04003374 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04003375 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04003376 fc_attach_transport(&lpfc_vport_transport_functions);
3377 if (lpfc_vport_transport_template == NULL) {
3378 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003379 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04003380 }
James Smart7ee5d432007-10-27 13:37:17 -04003381 }
dea31012005-04-17 16:05:31 -05003382 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05003383 if (error) {
dea31012005-04-17 16:05:31 -05003384 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04003385 if (lpfc_enable_npiv)
3386 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05003387 }
dea31012005-04-17 16:05:31 -05003388
3389 return error;
3390}
3391
James Smarte59058c2008-08-24 21:49:00 -04003392/**
3393 * lpfc_exit: lpfc module removal routine.
3394 *
3395 * This routine is invoked when the lpfc module is removed from the kernel.
3396 * The special kernel macro module_exit() is used to indicate the role of
3397 * this routine to the kernel as lpfc module exit point.
3398 */
dea31012005-04-17 16:05:31 -05003399static void __exit
3400lpfc_exit(void)
3401{
3402 pci_unregister_driver(&lpfc_driver);
3403 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04003404 if (lpfc_enable_npiv)
3405 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05003406}
3407
3408module_init(lpfc_init);
3409module_exit(lpfc_exit);
3410MODULE_LICENSE("GPL");
3411MODULE_DESCRIPTION(LPFC_MODULE_DESC);
3412MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
3413MODULE_VERSION("0:" LPFC_DRIVER_VERSION);