blob: 6a7a039e8904371e62f03244547f6b1ee1c5ff44 [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"
39#include "lpfc_disc.h"
40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050044#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc_version.h"
46
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050047static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050048static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
49static int lpfc_post_rcv_buf(struct lpfc_hba *);
50
51static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050052static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050053static DEFINE_IDR(lpfc_hba_index);
54
James Smarte59058c2008-08-24 21:49:00 -040055/**
56 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
57 * @phba: pointer to lpfc hba data structure.
58 *
59 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
60 * mailbox command. It retrieves the revision information from the HBA and
61 * collects the Vital Product Data (VPD) about the HBA for preparing the
62 * configuration of the HBA.
63 *
64 * Return codes:
65 * 0 - success.
66 * -ERESTART - requests the SLI layer to reset the HBA and try again.
67 * Any other value - indicates an error.
68 **/
dea31012005-04-17 16:05:31 -050069int
James Smart2e0fef82007-06-17 19:56:36 -050070lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050071{
72 lpfc_vpd_t *vp = &phba->vpd;
73 int i = 0, rc;
74 LPFC_MBOXQ_t *pmb;
75 MAILBOX_t *mb;
76 char *lpfc_vpd_data = NULL;
77 uint16_t offset = 0;
78 static char licensed[56] =
79 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040080 static int init_key = 1;
dea31012005-04-17 16:05:31 -050081
82 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
83 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050084 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050085 return -ENOMEM;
86 }
87
88 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050089 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050090
91 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040092 if (init_key) {
93 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050094
James Smart65a29c12006-07-06 15:50:50 -040095 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
96 *ptext = cpu_to_be32(*ptext);
97 init_key = 0;
98 }
dea31012005-04-17 16:05:31 -050099
100 lpfc_read_nv(phba, pmb);
101 memset((char*)mb->un.varRDnvp.rsvd3, 0,
102 sizeof (mb->un.varRDnvp.rsvd3));
103 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
104 sizeof (licensed));
105
106 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
107
108 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500109 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400110 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500111 "error, mbxCmd x%x READ_NVPARM, "
112 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500113 mb->mbxCommand, mb->mbxStatus);
114 mempool_free(pmb, phba->mbox_mem_pool);
115 return -ERESTART;
116 }
117 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500118 sizeof(phba->wwnn));
119 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
120 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500121 }
122
James Smart92d7f7b2007-06-17 19:56:38 -0500123 phba->sli3_options = 0x0;
124
dea31012005-04-17 16:05:31 -0500125 /* Setup and issue mailbox READ REV command */
126 lpfc_read_rev(phba, pmb);
127 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
128 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400130 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500131 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500132 mb->mbxCommand, mb->mbxStatus);
133 mempool_free( pmb, phba->mbox_mem_pool);
134 return -ERESTART;
135 }
136
James Smart92d7f7b2007-06-17 19:56:38 -0500137
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500138 /*
139 * The value of rr must be 1 since the driver set the cv field to 1.
140 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500141 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500142 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500143 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400145 "0440 Adapter failed to init, READ_REV has "
146 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500147 mempool_free(pmb, phba->mbox_mem_pool);
148 return -ERESTART;
dea31012005-04-17 16:05:31 -0500149 }
150
James Smart495a7142008-06-14 22:52:59 -0400151 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
152 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500153 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400154 }
James Smarted957682007-06-17 19:56:37 -0500155
dea31012005-04-17 16:05:31 -0500156 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500157 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500158 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500159 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
160 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
161 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
162 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500163 vp->rev.biuRev = mb->un.varRdRev.biuRev;
164 vp->rev.smRev = mb->un.varRdRev.smRev;
165 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
166 vp->rev.endecRev = mb->un.varRdRev.endecRev;
167 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
168 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
169 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
170 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
171 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
172 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
173
James Smart92d7f7b2007-06-17 19:56:38 -0500174 /* If the sli feature level is less then 9, we must
175 * tear down all RPIs and VPIs on link down if NPIV
176 * is enabled.
177 */
178 if (vp->rev.feaLevelHigh < 9)
179 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
180
dea31012005-04-17 16:05:31 -0500181 if (lpfc_is_LC_HBA(phba->pcidev->device))
182 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
183 sizeof (phba->RandomData));
184
dea31012005-04-17 16:05:31 -0500185 /* Get adapter VPD information */
186 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
187 if (!pmb->context2)
188 goto out_free_mbox;
189 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
190 if (!lpfc_vpd_data)
191 goto out_free_context2;
192
193 do {
194 lpfc_dump_mem(phba, pmb, offset);
195 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
196
197 if (rc != MBX_SUCCESS) {
198 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400199 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500200 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500201 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500202 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500203 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500204 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
205 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
dea31012005-04-17 16:05:31 -0500206 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500207 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500208 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500209 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
210 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500211
212 kfree(lpfc_vpd_data);
213out_free_context2:
214 kfree(pmb->context2);
215out_free_mbox:
216 mempool_free(pmb, phba->mbox_mem_pool);
217 return 0;
218}
219
James Smarte59058c2008-08-24 21:49:00 -0400220/**
221 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
222 * @phba: pointer to lpfc hba data structure.
223 * @pmboxq: pointer to the driver internal queue element for mailbox command.
224 *
225 * This is the completion handler for driver's configuring asynchronous event
226 * mailbox command to the device. If the mailbox command returns successfully,
227 * it will set internal async event support flag to 1; otherwise, it will
228 * set internal async event support flag to 0.
229 **/
James Smart57127f12007-10-27 13:37:05 -0400230static void
231lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
232{
233 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
234 phba->temp_sensor_support = 1;
235 else
236 phba->temp_sensor_support = 0;
237 mempool_free(pmboxq, phba->mbox_mem_pool);
238 return;
239}
240
James Smarte59058c2008-08-24 21:49:00 -0400241/**
242 * lpfc_config_port_post: Perform lpfc initialization after config port.
243 * @phba: pointer to lpfc hba data structure.
244 *
245 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
246 * command call. It performs all internal resource and state setups on the
247 * port: post IOCB buffers, enable appropriate host interrupt attentions,
248 * ELS ring timers, etc.
249 *
250 * Return codes
251 * 0 - success.
252 * Any other value - error.
253 **/
dea31012005-04-17 16:05:31 -0500254int
James Smart2e0fef82007-06-17 19:56:36 -0500255lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500256{
James Smart2e0fef82007-06-17 19:56:36 -0500257 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500258 LPFC_MBOXQ_t *pmb;
259 MAILBOX_t *mb;
260 struct lpfc_dmabuf *mp;
261 struct lpfc_sli *psli = &phba->sli;
262 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500263 int i, j;
264 int rc;
dea31012005-04-17 16:05:31 -0500265
James Smart7af67052007-10-27 13:38:11 -0400266 spin_lock_irq(&phba->hbalock);
267 /*
268 * If the Config port completed correctly the HBA is not
269 * over heated any more.
270 */
271 if (phba->over_temp_state == HBA_OVER_TEMP)
272 phba->over_temp_state = HBA_NORMAL_TEMP;
273 spin_unlock_irq(&phba->hbalock);
274
dea31012005-04-17 16:05:31 -0500275 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
276 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500277 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500278 return -ENOMEM;
279 }
280 mb = &pmb->mb;
281
dea31012005-04-17 16:05:31 -0500282 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500283 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500284 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500285 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400287 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500288 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500289 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500290 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500291 mp = (struct lpfc_dmabuf *) pmb->context1;
292 mempool_free( pmb, phba->mbox_mem_pool);
293 lpfc_mbuf_free(phba, mp->virt, mp->phys);
294 kfree(mp);
295 return -EIO;
296 }
297
298 mp = (struct lpfc_dmabuf *) pmb->context1;
299
James Smart2e0fef82007-06-17 19:56:36 -0500300 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500301 lpfc_mbuf_free(phba, mp->virt, mp->phys);
302 kfree(mp);
303 pmb->context1 = NULL;
304
James Smarta12e07b2006-12-02 13:35:30 -0500305 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500306 u64_to_wwn(phba->cfg_soft_wwnn,
307 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400308 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500309 u64_to_wwn(phba->cfg_soft_wwpn,
310 vport->fc_sparam.portName.u.wwn);
311 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500312 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500313 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500314 sizeof (struct lpfc_name));
315 /* If no serial number in VPD data, use low 6 bytes of WWNN */
316 /* This should be consolidated into parse_vpd ? - mr */
317 if (phba->SerialNumber[0] == 0) {
318 uint8_t *outptr;
319
James Smart2e0fef82007-06-17 19:56:36 -0500320 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500321 for (i = 0; i < 12; i++) {
322 status = *outptr++;
323 j = ((status & 0xf0) >> 4);
324 if (j <= 9)
325 phba->SerialNumber[i] =
326 (char)((uint8_t) 0x30 + (uint8_t) j);
327 else
328 phba->SerialNumber[i] =
329 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
330 i++;
331 j = (status & 0xf);
332 if (j <= 9)
333 phba->SerialNumber[i] =
334 (char)((uint8_t) 0x30 + (uint8_t) j);
335 else
336 phba->SerialNumber[i] =
337 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
338 }
339 }
340
dea31012005-04-17 16:05:31 -0500341 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500342 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500343 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500344 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400345 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500346 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500347 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500348 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500349 mempool_free( pmb, phba->mbox_mem_pool);
350 return -EIO;
351 }
352
353 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
354 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
355 phba->cfg_hba_queue_depth =
356 mb->un.varRdConfig.max_xri + 1;
357
358 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500359
360 /* Get the default values for Model Name and Description */
361 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
362
363 if ((phba->cfg_link_speed > LINK_SPEED_10G)
364 || ((phba->cfg_link_speed == LINK_SPEED_1G)
365 && !(phba->lmt & LMT_1Gb))
366 || ((phba->cfg_link_speed == LINK_SPEED_2G)
367 && !(phba->lmt & LMT_2Gb))
368 || ((phba->cfg_link_speed == LINK_SPEED_4G)
369 && !(phba->lmt & LMT_4Gb))
370 || ((phba->cfg_link_speed == LINK_SPEED_8G)
371 && !(phba->lmt & LMT_8Gb))
372 || ((phba->cfg_link_speed == LINK_SPEED_10G)
373 && !(phba->lmt & LMT_10Gb))) {
374 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500375 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400376 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500377 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500378 phba->cfg_link_speed);
379 phba->cfg_link_speed = LINK_SPEED_AUTO;
380 }
381
James Smart2e0fef82007-06-17 19:56:36 -0500382 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500383
James Smart0b727fe2007-10-27 13:37:25 -0400384 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500385 if (psli->ring[psli->extra_ring].cmdringaddr)
386 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500387 if (psli->ring[psli->fcp_ring].cmdringaddr)
388 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
389 if (psli->ring[psli->next_ring].cmdringaddr)
390 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
391
392 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500393 if (phba->sli_rev != 3)
394 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500395
396 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500397 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500398 status = readl(phba->HCregaddr);
399 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
400 if (psli->num_rings > 0)
401 status |= HC_R0INT_ENA;
402 if (psli->num_rings > 1)
403 status |= HC_R1INT_ENA;
404 if (psli->num_rings > 2)
405 status |= HC_R2INT_ENA;
406 if (psli->num_rings > 3)
407 status |= HC_R3INT_ENA;
408
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500409 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
410 (phba->cfg_poll & DISABLE_FCP_RING_INT))
411 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
412
dea31012005-04-17 16:05:31 -0500413 writel(status, phba->HCregaddr);
414 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500415 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500416
417 /*
418 * Setup the ring 0 (els) timeout handler
419 */
420 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500421 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500422 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
423 phba->hb_outstanding = 0;
424 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500425
426 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
427 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500428 pmb->vport = vport;
James Smart8aee9182006-08-31 12:27:57 -0400429 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400430 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400431 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500432 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400433 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500434 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500435 mb->mbxCommand, mb->mbxStatus);
436
437 /* Clear all interrupt enable conditions */
438 writel(0, phba->HCregaddr);
439 readl(phba->HCregaddr); /* flush */
440 /* Clear all pending interrupts */
441 writel(0xffffffff, phba->HAregaddr);
442 readl(phba->HAregaddr); /* flush */
443
James Smart2e0fef82007-06-17 19:56:36 -0500444 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400445 if (rc != MBX_BUSY)
446 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500447 return -EIO;
448 }
449 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400450 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
451 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
452 pmb->mbox_cmpl = lpfc_config_async_cmpl;
453 pmb->vport = phba->pport;
454 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500455
James Smart57127f12007-10-27 13:37:05 -0400456 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
457 lpfc_printf_log(phba,
458 KERN_ERR,
459 LOG_INIT,
460 "0456 Adapter failed to issue "
461 "ASYNCEVT_ENABLE mbox status x%x \n.",
462 rc);
463 mempool_free(pmb, phba->mbox_mem_pool);
464 }
James Smartce8b3ce2006-07-06 15:50:36 -0400465 return (0);
466}
467
James Smarte59058c2008-08-24 21:49:00 -0400468/**
469 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
470 * @phba: pointer to lpfc HBA data structure.
471 *
472 * This routine will do LPFC uninitialization before the HBA is reset when
473 * bringing down the SLI Layer.
474 *
475 * Return codes
476 * 0 - success.
477 * Any other value - error.
478 **/
dea31012005-04-17 16:05:31 -0500479int
James Smart2e0fef82007-06-17 19:56:36 -0500480lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500481{
James Smart1b32f6a2008-02-08 18:49:39 -0500482 struct lpfc_vport **vports;
483 int i;
dea31012005-04-17 16:05:31 -0500484 /* Disable interrupts */
485 writel(0, phba->HCregaddr);
486 readl(phba->HCregaddr); /* flush */
487
James Smart1b32f6a2008-02-08 18:49:39 -0500488 if (phba->pport->load_flag & FC_UNLOADING)
489 lpfc_cleanup_discovery_resources(phba->pport);
490 else {
491 vports = lpfc_create_vport_work_array(phba);
492 if (vports != NULL)
493 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
494 lpfc_cleanup_discovery_resources(vports[i]);
495 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500496 }
497 return 0;
dea31012005-04-17 16:05:31 -0500498}
499
James Smarte59058c2008-08-24 21:49:00 -0400500/**
501 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
502 * @phba: pointer to lpfc HBA data structure.
503 *
504 * This routine will do uninitialization after the HBA is reset when bring
505 * down the SLI Layer.
506 *
507 * Return codes
508 * 0 - sucess.
509 * Any other value - error.
510 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500511int
James Smart2e0fef82007-06-17 19:56:36 -0500512lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500513{
514 struct lpfc_sli *psli = &phba->sli;
515 struct lpfc_sli_ring *pring;
516 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500517 struct lpfc_iocbq *iocb;
518 IOCB_t *cmd = NULL;
519 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500520 int i;
521
James Smart92d7f7b2007-06-17 19:56:38 -0500522 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
523 lpfc_sli_hbqbuf_free_all(phba);
524 else {
525 /* Cleanup preposted buffers on the ELS ring */
526 pring = &psli->ring[LPFC_ELS_RING];
527 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
528 list_del(&mp->list);
529 pring->postbufq_cnt--;
530 lpfc_mbuf_free(phba, mp->virt, mp->phys);
531 kfree(mp);
532 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500533 }
534
James Smart09372822008-01-11 01:52:54 -0500535 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500536 for (i = 0; i < psli->num_rings; i++) {
537 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500538
539 /* At this point in time the HBA is either reset or DOA. Either
540 * way, nothing should be on txcmplq as it will NEVER complete.
541 */
542 list_splice_init(&pring->txcmplq, &completions);
543 pring->txcmplq_cnt = 0;
544 spin_unlock_irq(&phba->hbalock);
545
546 while (!list_empty(&completions)) {
547 iocb = list_get_first(&completions, struct lpfc_iocbq,
548 list);
549 cmd = &iocb->iocb;
550 list_del_init(&iocb->list);
551
552 if (!iocb->iocb_cmpl)
553 lpfc_sli_release_iocbq(phba, iocb);
554 else {
555 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
556 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
557 (iocb->iocb_cmpl) (phba, iocb, iocb);
558 }
559 }
560
Jamie Wellnitz41415862006-02-28 19:25:27 -0500561 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500562 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500563 }
James Smart09372822008-01-11 01:52:54 -0500564 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500565
566 return 0;
567}
568
James Smarte59058c2008-08-24 21:49:00 -0400569/**
570 * lpfc_hb_timeout: The HBA-timer timeout handler.
571 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
572 *
573 * This is the HBA-timer timeout handler registered to the lpfc driver. When
574 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
575 * work-port-events bitmap and the worker thread is notified. This timeout
576 * event will be used by the worker thread to invoke the actual timeout
577 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
578 * be performed in the timeout handler and the HBA timeout event bit shall
579 * be cleared by the worker thread after it has taken the event bitmap out.
580 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100581static void
James Smart858c9f62007-06-17 19:56:39 -0500582lpfc_hb_timeout(unsigned long ptr)
583{
584 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400585 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500586 unsigned long iflag;
587
588 phba = (struct lpfc_hba *)ptr;
589 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400590 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
591 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500592 phba->pport->work_port_events |= WORKER_HB_TMO;
593 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
594
James Smart5e9d9b82008-06-14 22:52:53 -0400595 if (!tmo_posted)
596 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500597 return;
598}
599
James Smarte59058c2008-08-24 21:49:00 -0400600/**
601 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
602 * @phba: pointer to lpfc hba data structure.
603 * @pmboxq: pointer to the driver internal queue element for mailbox command.
604 *
605 * This is the callback function to the lpfc heart-beat mailbox command.
606 * If configured, the lpfc driver issues the heart-beat mailbox command to
607 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
608 * heart-beat mailbox command is issued, the driver shall set up heart-beat
609 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
610 * heart-beat outstanding state. Once the mailbox command comes back and
611 * no error conditions detected, the heart-beat mailbox command timer is
612 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
613 * state is cleared for the next heart-beat. If the timer expired with the
614 * heart-beat outstanding state set, the driver will put the HBA offline.
615 **/
James Smart858c9f62007-06-17 19:56:39 -0500616static void
617lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
618{
619 unsigned long drvr_flag;
620
621 spin_lock_irqsave(&phba->hbalock, drvr_flag);
622 phba->hb_outstanding = 0;
623 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
624
625 mempool_free(pmboxq, phba->mbox_mem_pool);
626 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
627 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400628 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500629 mod_timer(&phba->hb_tmofunc,
630 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
631 return;
632}
633
James Smarte59058c2008-08-24 21:49:00 -0400634/**
635 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
636 * @phba: pointer to lpfc hba data structure.
637 *
638 * This is the actual HBA-timer timeout handler to be invoked by the worker
639 * thread whenever the HBA timer fired and HBA-timeout event posted. This
640 * handler performs any periodic operations needed for the device. If such
641 * periodic event has already been attended to either in the interrupt handler
642 * or by processing slow-ring or fast-ring events within the HBA-timer
643 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
644 * the timer for the next timeout period. If lpfc heart-beat mailbox command
645 * is configured and there is no heart-beat mailbox command outstanding, a
646 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
647 * has been a heart-beat mailbox command outstanding, the HBA shall be put
648 * to offline.
649 **/
James Smart858c9f62007-06-17 19:56:39 -0500650void
651lpfc_hb_timeout_handler(struct lpfc_hba *phba)
652{
653 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500654 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500655 int retval;
656 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500657 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500658
659 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400660 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500661 (phba->pport->fc_flag & FC_OFFLINE_MODE))
662 return;
663
664 spin_lock_irq(&phba->pport->work_port_lock);
665 /* If the timer is already canceled do nothing */
666 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
667 spin_unlock_irq(&phba->pport->work_port_lock);
668 return;
669 }
670
671 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
672 jiffies)) {
673 spin_unlock_irq(&phba->pport->work_port_lock);
674 if (!phba->hb_outstanding)
675 mod_timer(&phba->hb_tmofunc,
676 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
677 else
678 mod_timer(&phba->hb_tmofunc,
679 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
680 return;
681 }
682 spin_unlock_irq(&phba->pport->work_port_lock);
683
James Smart0ff10d42008-01-11 01:52:36 -0500684 if (phba->elsbuf_cnt &&
685 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
686 spin_lock_irq(&phba->hbalock);
687 list_splice_init(&phba->elsbuf, &completions);
688 phba->elsbuf_cnt = 0;
689 phba->elsbuf_prev_cnt = 0;
690 spin_unlock_irq(&phba->hbalock);
691
692 while (!list_empty(&completions)) {
693 list_remove_head(&completions, buf_ptr,
694 struct lpfc_dmabuf, list);
695 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
696 kfree(buf_ptr);
697 }
698 }
699 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
700
James Smart858c9f62007-06-17 19:56:39 -0500701 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500702 if (phba->cfg_enable_hba_heartbeat) {
703 if (!phba->hb_outstanding) {
704 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
705 if (!pmboxq) {
706 mod_timer(&phba->hb_tmofunc,
707 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
708 return;
709 }
710
711 lpfc_heart_beat(phba, pmboxq);
712 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
713 pmboxq->vport = phba->pport;
714 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
715
716 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
717 mempool_free(pmboxq, phba->mbox_mem_pool);
718 mod_timer(&phba->hb_tmofunc,
719 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
720 return;
721 }
James Smart858c9f62007-06-17 19:56:39 -0500722 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500723 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
724 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500725 return;
James Smart13815c82008-01-11 01:52:48 -0500726 } else {
727 /*
728 * If heart beat timeout called with hb_outstanding set
729 * we need to take the HBA offline.
730 */
731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
732 "0459 Adapter heartbeat failure, "
733 "taking this port offline.\n");
734
735 spin_lock_irq(&phba->hbalock);
736 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
737 spin_unlock_irq(&phba->hbalock);
738
739 lpfc_offline_prep(phba);
740 lpfc_offline(phba);
741 lpfc_unblock_mgmt_io(phba);
742 phba->link_state = LPFC_HBA_ERROR;
743 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500744 }
James Smart858c9f62007-06-17 19:56:39 -0500745 }
746}
747
James Smarte59058c2008-08-24 21:49:00 -0400748/**
749 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
750 * @phba: pointer to lpfc hba data structure.
751 *
752 * This routine is called to bring the HBA offline when HBA hardware error
753 * other than Port Error 6 has been detected.
754 **/
James Smart09372822008-01-11 01:52:54 -0500755static void
756lpfc_offline_eratt(struct lpfc_hba *phba)
757{
758 struct lpfc_sli *psli = &phba->sli;
759
760 spin_lock_irq(&phba->hbalock);
761 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
762 spin_unlock_irq(&phba->hbalock);
763 lpfc_offline_prep(phba);
764
765 lpfc_offline(phba);
766 lpfc_reset_barrier(phba);
767 lpfc_sli_brdreset(phba);
768 lpfc_hba_down_post(phba);
769 lpfc_sli_brdready(phba, HS_MBRDY);
770 lpfc_unblock_mgmt_io(phba);
771 phba->link_state = LPFC_HBA_ERROR;
772 return;
773}
774
James Smarte59058c2008-08-24 21:49:00 -0400775/**
776 * lpfc_handle_eratt: The HBA hardware error handler.
777 * @phba: pointer to lpfc hba data structure.
778 *
779 * This routine is invoked to handle the following HBA hardware error
780 * conditions:
781 * 1 - HBA error attention interrupt
782 * 2 - DMA ring index out of range
783 * 3 - Mailbox command came back as unknown
784 **/
dea31012005-04-17 16:05:31 -0500785void
James Smart2e0fef82007-06-17 19:56:36 -0500786lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500787{
James Smart2e0fef82007-06-17 19:56:36 -0500788 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500789 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500790 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400791 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400792 unsigned long temperature;
793 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500794 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -0500795
Linas Vepstas8d63f372007-02-14 14:28:36 -0600796 /* If the pci channel is offline, ignore possible errors,
797 * since we cannot communicate with the pci card anyway. */
798 if (pci_channel_offline(phba->pcidev))
799 return;
James Smart13815c82008-01-11 01:52:48 -0500800 /* If resets are disabled then leave the HBA alone and return */
801 if (!phba->cfg_enable_hba_reset)
802 return;
dea31012005-04-17 16:05:31 -0500803
James Smart97eab632008-04-07 10:16:05 -0400804 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500805 /* Re-establishing Link */
806 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400807 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500808 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400809 phba->work_hs,
dea31012005-04-17 16:05:31 -0500810 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400811
James Smart92d7f7b2007-06-17 19:56:38 -0500812 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500813 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500814 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500815
816 /*
817 * Firmware stops when it triggled erratt with HS_FFER6.
818 * That could cause the I/Os dropped by the firmware.
819 * Error iocb (I/O) on txcmplq and let the SCSI layer
820 * retry it after re-establishing link.
821 */
822 pring = &psli->ring[psli->fcp_ring];
823 lpfc_sli_abort_iocb_ring(phba, pring);
824
dea31012005-04-17 16:05:31 -0500825 /*
826 * There was a firmware error. Take the hba offline and then
827 * attempt to restart it.
828 */
James Smart46fa3112007-04-25 09:51:45 -0400829 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500830 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500831 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500832 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400833 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500834 return;
835 }
James Smart46fa3112007-04-25 09:51:45 -0400836 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400837 } else if (phba->work_hs & HS_CRIT_TEMP) {
838 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
839 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
840 temp_event_data.event_code = LPFC_CRIT_TEMP;
841 temp_event_data.data = (uint32_t)temperature;
842
843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
844 "0459 Adapter maximum temperature exceeded "
845 "(%ld), taking this port offline "
846 "Data: x%x x%x x%x\n",
847 temperature, phba->work_hs,
848 phba->work_status[0], phba->work_status[1]);
849
850 shost = lpfc_shost_from_vport(phba->pport);
851 fc_host_post_vendor_event(shost, fc_get_event_number(),
852 sizeof(temp_event_data),
853 (char *) &temp_event_data,
854 SCSI_NL_VID_TYPE_PCI
855 | PCI_VENDOR_ID_EMULEX);
856
James Smart7af67052007-10-27 13:38:11 -0400857 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400858 phba->over_temp_state = HBA_OVER_TEMP;
859 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500860 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400861
dea31012005-04-17 16:05:31 -0500862 } else {
863 /* The if clause above forces this code path when the status
864 * failure is a value other than FFER6. Do not call the offline
865 * twice. This is the adapter hardware error path.
866 */
867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400868 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500869 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400870 phba->work_hs,
dea31012005-04-17 16:05:31 -0500871 phba->work_status[0], phba->work_status[1]);
872
James Smartd2873e42006-08-18 17:46:43 -0400873 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500874 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500875 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400876 sizeof(event_data), (char *) &event_data,
877 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
878
James Smart09372822008-01-11 01:52:54 -0500879 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500880 }
881}
882
James Smarte59058c2008-08-24 21:49:00 -0400883/**
884 * lpfc_handle_latt: The HBA link event handler.
885 * @phba: pointer to lpfc hba data structure.
886 *
887 * This routine is invoked from the worker thread to handle a HBA host
888 * attention link event.
889 **/
dea31012005-04-17 16:05:31 -0500890void
James Smart2e0fef82007-06-17 19:56:36 -0500891lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500892{
James Smart2e0fef82007-06-17 19:56:36 -0500893 struct lpfc_vport *vport = phba->pport;
894 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500895 LPFC_MBOXQ_t *pmb;
896 volatile uint32_t control;
897 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500898 int rc = 0;
dea31012005-04-17 16:05:31 -0500899
900 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500901 if (!pmb) {
902 rc = 1;
dea31012005-04-17 16:05:31 -0500903 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500904 }
dea31012005-04-17 16:05:31 -0500905
906 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500907 if (!mp) {
908 rc = 2;
dea31012005-04-17 16:05:31 -0500909 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500910 }
dea31012005-04-17 16:05:31 -0500911
912 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500913 if (!mp->virt) {
914 rc = 3;
dea31012005-04-17 16:05:31 -0500915 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500916 }
dea31012005-04-17 16:05:31 -0500917
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500918 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400919 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500920
921 psli->slistat.link_event++;
922 lpfc_read_la(phba, pmb, mp);
923 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500924 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -0400925 /* Block ELS IOCBs until we have processed this mbox command */
926 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -0400927 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500928 if (rc == MBX_NOT_FINISHED) {
929 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500930 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500931 }
dea31012005-04-17 16:05:31 -0500932
933 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500934 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500935 writel(HA_LATT, phba->HAregaddr);
936 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500937 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500938
939 return;
940
James Smart14691152006-12-02 13:34:28 -0500941lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -0400942 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -0500943 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500944lpfc_handle_latt_free_mp:
945 kfree(mp);
946lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400947 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500948lpfc_handle_latt_err_exit:
949 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500950 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500951 psli->sli_flag |= LPFC_PROCESS_LA;
952 control = readl(phba->HCregaddr);
953 control |= HC_LAINT_ENA;
954 writel(control, phba->HCregaddr);
955 readl(phba->HCregaddr); /* flush */
956
957 /* Clear Link Attention in HA REG */
958 writel(HA_LATT, phba->HAregaddr);
959 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500960 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500961 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500962 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500963
James Smart09372822008-01-11 01:52:54 -0500964 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
965 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500966
967 return;
968}
969
James Smarte59058c2008-08-24 21:49:00 -0400970/**
971 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
972 * @phba: pointer to lpfc hba data structure.
973 * @vpd: pointer to the vital product data.
974 * @len: length of the vital product data in bytes.
975 *
976 * This routine parses the Vital Product Data (VPD). The VPD is treated as
977 * an array of characters. In this routine, the ModelName, ProgramType, and
978 * ModelDesc, etc. fields of the phba data structure will be populated.
979 *
980 * Return codes
981 * 0 - pointer to the VPD passed in is NULL
982 * 1 - success
983 **/
dea31012005-04-17 16:05:31 -0500984static int
James Smart2e0fef82007-06-17 19:56:36 -0500985lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500986{
987 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500988 int Length;
dea31012005-04-17 16:05:31 -0500989 int i, j;
990 int finished = 0;
991 int index = 0;
992
993 if (!vpd)
994 return 0;
995
996 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500997 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400998 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500999 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1000 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001001 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001002 switch (vpd[index]) {
1003 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001004 case 0x91:
dea31012005-04-17 16:05:31 -05001005 index += 1;
1006 lenlo = vpd[index];
1007 index += 1;
1008 lenhi = vpd[index];
1009 index += 1;
1010 i = ((((unsigned short)lenhi) << 8) + lenlo);
1011 index += i;
1012 break;
1013 case 0x90:
1014 index += 1;
1015 lenlo = vpd[index];
1016 index += 1;
1017 lenhi = vpd[index];
1018 index += 1;
1019 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001020 if (Length > len - index)
1021 Length = len - index;
dea31012005-04-17 16:05:31 -05001022 while (Length > 0) {
1023 /* Look for Serial Number */
1024 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1025 index += 2;
1026 i = vpd[index];
1027 index += 1;
1028 j = 0;
1029 Length -= (3+i);
1030 while(i--) {
1031 phba->SerialNumber[j++] = vpd[index++];
1032 if (j == 31)
1033 break;
1034 }
1035 phba->SerialNumber[j] = 0;
1036 continue;
1037 }
1038 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1039 phba->vpd_flag |= VPD_MODEL_DESC;
1040 index += 2;
1041 i = vpd[index];
1042 index += 1;
1043 j = 0;
1044 Length -= (3+i);
1045 while(i--) {
1046 phba->ModelDesc[j++] = vpd[index++];
1047 if (j == 255)
1048 break;
1049 }
1050 phba->ModelDesc[j] = 0;
1051 continue;
1052 }
1053 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1054 phba->vpd_flag |= VPD_MODEL_NAME;
1055 index += 2;
1056 i = vpd[index];
1057 index += 1;
1058 j = 0;
1059 Length -= (3+i);
1060 while(i--) {
1061 phba->ModelName[j++] = vpd[index++];
1062 if (j == 79)
1063 break;
1064 }
1065 phba->ModelName[j] = 0;
1066 continue;
1067 }
1068 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1069 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1070 index += 2;
1071 i = vpd[index];
1072 index += 1;
1073 j = 0;
1074 Length -= (3+i);
1075 while(i--) {
1076 phba->ProgramType[j++] = vpd[index++];
1077 if (j == 255)
1078 break;
1079 }
1080 phba->ProgramType[j] = 0;
1081 continue;
1082 }
1083 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1084 phba->vpd_flag |= VPD_PORT;
1085 index += 2;
1086 i = vpd[index];
1087 index += 1;
1088 j = 0;
1089 Length -= (3+i);
1090 while(i--) {
1091 phba->Port[j++] = vpd[index++];
1092 if (j == 19)
1093 break;
1094 }
1095 phba->Port[j] = 0;
1096 continue;
1097 }
1098 else {
1099 index += 2;
1100 i = vpd[index];
1101 index += 1;
1102 index += i;
1103 Length -= (3 + i);
1104 }
1105 }
1106 finished = 0;
1107 break;
1108 case 0x78:
1109 finished = 1;
1110 break;
1111 default:
1112 index ++;
1113 break;
1114 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001115 }
dea31012005-04-17 16:05:31 -05001116
1117 return(1);
1118}
1119
James Smarte59058c2008-08-24 21:49:00 -04001120/**
1121 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1122 * @phba: pointer to lpfc hba data structure.
1123 * @mdp: pointer to the data structure to hold the derived model name.
1124 * @descp: pointer to the data structure to hold the derived description.
1125 *
1126 * This routine retrieves HBA's description based on its registered PCI device
1127 * ID. The @descp passed into this function points to an array of 256 chars. It
1128 * shall be returned with the model name, maximum speed, and the host bus type.
1129 * The @mdp passed into this function points to an array of 80 chars. When the
1130 * function returns, the @mdp will be filled with the model name.
1131 **/
dea31012005-04-17 16:05:31 -05001132static void
James Smart2e0fef82007-06-17 19:56:36 -05001133lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001134{
1135 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001136 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001137 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001138 struct {
1139 char * name;
1140 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001141 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001142 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001143
1144 if (mdp && mdp[0] != '\0'
1145 && descp && descp[0] != '\0')
1146 return;
1147
1148 if (phba->lmt & LMT_10Gb)
1149 max_speed = 10;
1150 else if (phba->lmt & LMT_8Gb)
1151 max_speed = 8;
1152 else if (phba->lmt & LMT_4Gb)
1153 max_speed = 4;
1154 else if (phba->lmt & LMT_2Gb)
1155 max_speed = 2;
1156 else
1157 max_speed = 1;
dea31012005-04-17 16:05:31 -05001158
1159 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001160
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001161 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001162 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001163 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001164 break;
dea31012005-04-17 16:05:31 -05001165 case PCI_DEVICE_ID_SUPERFLY:
1166 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001167 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001168 else
James Smart18a3b592006-12-02 13:35:08 -05001169 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001170 break;
1171 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001172 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001173 break;
1174 case PCI_DEVICE_ID_CENTAUR:
1175 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001176 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001177 else
James Smart18a3b592006-12-02 13:35:08 -05001178 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001179 break;
1180 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001181 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001182 break;
1183 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001184 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001185 break;
1186 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001187 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001188 break;
1189 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001190 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001191 break;
1192 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001193 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001194 break;
1195 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001196 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001197 break;
1198 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001199 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001200 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001201 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001202 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001203 break;
1204 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001205 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001206 break;
1207 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001208 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001209 break;
1210 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001211 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001212 break;
1213 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001214 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001215 break;
dea31012005-04-17 16:05:31 -05001216 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001217 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001218 break;
1219 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001220 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001221 break;
1222 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001223 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001224 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001225 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001226 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001227 break;
1228 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001229 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001230 break;
dea31012005-04-17 16:05:31 -05001231 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001232 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001233 break;
1234 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001235 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001236 break;
1237 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001238 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001239 break;
1240 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001241 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001242 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001243 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001244 m = (typeof(m)){"LP11000-S", max_speed,
1245 "PCI-X2"};
1246 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001247 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001248 m = (typeof(m)){"LPe11000-S", max_speed,
1249 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001250 break;
James Smartb87eab32007-04-25 09:53:28 -04001251 case PCI_DEVICE_ID_SAT:
1252 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1253 break;
1254 case PCI_DEVICE_ID_SAT_MID:
1255 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1256 break;
1257 case PCI_DEVICE_ID_SAT_SMB:
1258 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1259 break;
1260 case PCI_DEVICE_ID_SAT_DCSP:
1261 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1262 break;
1263 case PCI_DEVICE_ID_SAT_SCSP:
1264 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1265 break;
1266 case PCI_DEVICE_ID_SAT_S:
1267 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1268 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001269 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001270 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001271 break;
dea31012005-04-17 16:05:31 -05001272 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001273
1274 if (mdp && mdp[0] == '\0')
1275 snprintf(mdp, 79,"%s", m.name);
1276 if (descp && descp[0] == '\0')
1277 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001278 "Emulex %s %dGb %s Fibre Channel Adapter",
1279 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001280}
1281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
1283 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1284 * @phba: pointer to lpfc hba data structure.
1285 * @pring: pointer to a IOCB ring.
1286 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1287 *
1288 * This routine posts a given number of IOCBs with the associated DMA buffer
1289 * descriptors specified by the cnt argument to the given IOCB ring.
1290 *
1291 * Return codes
1292 * The number of IOCBs NOT able to be posted to the IOCB ring.
1293 **/
dea31012005-04-17 16:05:31 -05001294int
James Smart495a7142008-06-14 22:52:59 -04001295lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001296{
1297 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001298 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001299 struct lpfc_dmabuf *mp1, *mp2;
1300
1301 cnt += pring->missbufcnt;
1302
1303 /* While there are buffers to post */
1304 while (cnt > 0) {
1305 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001306 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001307 if (iocb == NULL) {
1308 pring->missbufcnt = cnt;
1309 return cnt;
1310 }
dea31012005-04-17 16:05:31 -05001311 icmd = &iocb->iocb;
1312
1313 /* 2 buffers can be posted per command */
1314 /* Allocate buffer to post */
1315 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1316 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001317 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1318 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001319 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001320 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001321 pring->missbufcnt = cnt;
1322 return cnt;
1323 }
1324
1325 INIT_LIST_HEAD(&mp1->list);
1326 /* Allocate buffer to post */
1327 if (cnt > 1) {
1328 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1329 if (mp2)
1330 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1331 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001332 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001333 kfree(mp2);
dea31012005-04-17 16:05:31 -05001334 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1335 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001336 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001337 pring->missbufcnt = cnt;
1338 return cnt;
1339 }
1340
1341 INIT_LIST_HEAD(&mp2->list);
1342 } else {
1343 mp2 = NULL;
1344 }
1345
1346 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1347 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1348 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1349 icmd->ulpBdeCount = 1;
1350 cnt--;
1351 if (mp2) {
1352 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1353 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1354 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1355 cnt--;
1356 icmd->ulpBdeCount = 2;
1357 }
1358
1359 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1360 icmd->ulpLe = 1;
1361
dea31012005-04-17 16:05:31 -05001362 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1363 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1364 kfree(mp1);
1365 cnt++;
1366 if (mp2) {
1367 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1368 kfree(mp2);
1369 cnt++;
1370 }
James Bottomley604a3e32005-10-29 10:28:33 -05001371 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001372 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001373 return cnt;
1374 }
dea31012005-04-17 16:05:31 -05001375 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001376 if (mp2)
dea31012005-04-17 16:05:31 -05001377 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001378 }
1379 pring->missbufcnt = 0;
1380 return 0;
1381}
1382
James Smarte59058c2008-08-24 21:49:00 -04001383/**
1384 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1385 * @phba: pointer to lpfc hba data structure.
1386 *
1387 * This routine posts initial receive IOCB buffers to the ELS ring. The
1388 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1389 * set to 64 IOCBs.
1390 *
1391 * Return codes
1392 * 0 - success (currently always success)
1393 **/
dea31012005-04-17 16:05:31 -05001394static int
James Smart2e0fef82007-06-17 19:56:36 -05001395lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001396{
1397 struct lpfc_sli *psli = &phba->sli;
1398
1399 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001400 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001401 /* Ring 2 - FCP no buffers needed */
1402
1403 return 0;
1404}
1405
1406#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1407
James Smarte59058c2008-08-24 21:49:00 -04001408/**
1409 * lpfc_sha_init: Set up initial array of hash table entries.
1410 * @HashResultPointer: pointer to an array as hash table.
1411 *
1412 * This routine sets up the initial values to the array of hash table entries
1413 * for the LC HBAs.
1414 **/
dea31012005-04-17 16:05:31 -05001415static void
1416lpfc_sha_init(uint32_t * HashResultPointer)
1417{
1418 HashResultPointer[0] = 0x67452301;
1419 HashResultPointer[1] = 0xEFCDAB89;
1420 HashResultPointer[2] = 0x98BADCFE;
1421 HashResultPointer[3] = 0x10325476;
1422 HashResultPointer[4] = 0xC3D2E1F0;
1423}
1424
James Smarte59058c2008-08-24 21:49:00 -04001425/**
1426 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1427 * @HashResultPointer: pointer to an initial/result hash table.
1428 * @HashWorkingPointer: pointer to an working hash table.
1429 *
1430 * This routine iterates an initial hash table pointed by @HashResultPointer
1431 * with the values from the working hash table pointeed by @HashWorkingPointer.
1432 * The results are putting back to the initial hash table, returned through
1433 * the @HashResultPointer as the result hash table.
1434 **/
dea31012005-04-17 16:05:31 -05001435static void
1436lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1437{
1438 int t;
1439 uint32_t TEMP;
1440 uint32_t A, B, C, D, E;
1441 t = 16;
1442 do {
1443 HashWorkingPointer[t] =
1444 S(1,
1445 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1446 8] ^
1447 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1448 } while (++t <= 79);
1449 t = 0;
1450 A = HashResultPointer[0];
1451 B = HashResultPointer[1];
1452 C = HashResultPointer[2];
1453 D = HashResultPointer[3];
1454 E = HashResultPointer[4];
1455
1456 do {
1457 if (t < 20) {
1458 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1459 } else if (t < 40) {
1460 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1461 } else if (t < 60) {
1462 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1463 } else {
1464 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1465 }
1466 TEMP += S(5, A) + E + HashWorkingPointer[t];
1467 E = D;
1468 D = C;
1469 C = S(30, B);
1470 B = A;
1471 A = TEMP;
1472 } while (++t <= 79);
1473
1474 HashResultPointer[0] += A;
1475 HashResultPointer[1] += B;
1476 HashResultPointer[2] += C;
1477 HashResultPointer[3] += D;
1478 HashResultPointer[4] += E;
1479
1480}
1481
James Smarte59058c2008-08-24 21:49:00 -04001482/**
1483 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1484 * @RandomChallenge: pointer to the entry of host challenge random number array.
1485 * @HashWorking: pointer to the entry of the working hash array.
1486 *
1487 * This routine calculates the working hash array referred by @HashWorking
1488 * from the challenge random numbers associated with the host, referred by
1489 * @RandomChallenge. The result is put into the entry of the working hash
1490 * array and returned by reference through @HashWorking.
1491 **/
dea31012005-04-17 16:05:31 -05001492static void
1493lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1494{
1495 *HashWorking = (*RandomChallenge ^ *HashWorking);
1496}
1497
James Smarte59058c2008-08-24 21:49:00 -04001498/**
1499 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1500 * @phba: pointer to lpfc hba data structure.
1501 * @hbainit: pointer to an array of unsigned 32-bit integers.
1502 *
1503 * This routine performs the special handling for LC HBA initialization.
1504 **/
dea31012005-04-17 16:05:31 -05001505void
1506lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1507{
1508 int t;
1509 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001510 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001511
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001512 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001513 if (!HashWorking)
1514 return;
1515
dea31012005-04-17 16:05:31 -05001516 HashWorking[0] = HashWorking[78] = *pwwnn++;
1517 HashWorking[1] = HashWorking[79] = *pwwnn;
1518
1519 for (t = 0; t < 7; t++)
1520 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1521
1522 lpfc_sha_init(hbainit);
1523 lpfc_sha_iterate(hbainit, HashWorking);
1524 kfree(HashWorking);
1525}
1526
James Smarte59058c2008-08-24 21:49:00 -04001527/**
1528 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1529 * @vport: pointer to a virtual N_Port data structure.
1530 *
1531 * This routine performs the necessary cleanups before deleting the @vport.
1532 * It invokes the discovery state machine to perform necessary state
1533 * transitions and to release the ndlps associated with the @vport. Note,
1534 * the physical port is treated as @vport 0.
1535 **/
James Smart87af33f2007-10-27 13:37:43 -04001536void
James Smart2e0fef82007-06-17 19:56:36 -05001537lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001538{
James Smart87af33f2007-10-27 13:37:43 -04001539 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001540 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001541 int i = 0;
dea31012005-04-17 16:05:31 -05001542
James Smart87af33f2007-10-27 13:37:43 -04001543 if (phba->link_state > LPFC_LINK_DOWN)
1544 lpfc_port_link_failure(vport);
1545
1546 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001547 if (!NLP_CHK_NODE_ACT(ndlp)) {
1548 ndlp = lpfc_enable_node(vport, ndlp,
1549 NLP_STE_UNUSED_NODE);
1550 if (!ndlp)
1551 continue;
1552 spin_lock_irq(&phba->ndlp_lock);
1553 NLP_SET_FREE_REQ(ndlp);
1554 spin_unlock_irq(&phba->ndlp_lock);
1555 /* Trigger the release of the ndlp memory */
1556 lpfc_nlp_put(ndlp);
1557 continue;
1558 }
1559 spin_lock_irq(&phba->ndlp_lock);
1560 if (NLP_CHK_FREE_REQ(ndlp)) {
1561 /* The ndlp should not be in memory free mode already */
1562 spin_unlock_irq(&phba->ndlp_lock);
1563 continue;
1564 } else
1565 /* Indicate request for freeing ndlp memory */
1566 NLP_SET_FREE_REQ(ndlp);
1567 spin_unlock_irq(&phba->ndlp_lock);
1568
James Smart58da1ff2008-04-07 10:15:56 -04001569 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1570 ndlp->nlp_DID == Fabric_DID) {
1571 /* Just free up ndlp with Fabric_DID for vports */
1572 lpfc_nlp_put(ndlp);
1573 continue;
1574 }
1575
James Smart87af33f2007-10-27 13:37:43 -04001576 if (ndlp->nlp_type & NLP_FABRIC)
1577 lpfc_disc_state_machine(vport, ndlp, NULL,
1578 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001579
James Smart87af33f2007-10-27 13:37:43 -04001580 lpfc_disc_state_machine(vport, ndlp, NULL,
1581 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001582
James Smart87af33f2007-10-27 13:37:43 -04001583 }
1584
James Smarta8adb832007-10-27 13:37:53 -04001585 /* At this point, ALL ndlp's should be gone
1586 * because of the previous NLP_EVT_DEVICE_RM.
1587 * Lets wait for this to happen, if needed.
1588 */
James Smart87af33f2007-10-27 13:37:43 -04001589 while (!list_empty(&vport->fc_nodes)) {
1590
James Smarta8adb832007-10-27 13:37:53 -04001591 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001592 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001593 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001594 list_for_each_entry_safe(ndlp, next_ndlp,
1595 &vport->fc_nodes, nlp_listp) {
1596 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1597 LOG_NODE,
1598 "0282: did:x%x ndlp:x%p "
1599 "usgmap:x%x refcnt:%d\n",
1600 ndlp->nlp_DID, (void *)ndlp,
1601 ndlp->nlp_usg_map,
1602 atomic_read(
1603 &ndlp->kref.refcount));
1604 }
James Smarta8adb832007-10-27 13:37:53 -04001605 break;
James Smart87af33f2007-10-27 13:37:43 -04001606 }
James Smarta8adb832007-10-27 13:37:53 -04001607
1608 /* Wait for any activity on ndlps to settle */
1609 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001610 }
dea31012005-04-17 16:05:31 -05001611 return;
1612}
1613
James Smarte59058c2008-08-24 21:49:00 -04001614/**
1615 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1616 * @vport: pointer to a virtual N_Port data structure.
1617 *
1618 * This routine stops all the timers associated with a @vport. This function
1619 * is invoked before disabling or deleting a @vport. Note that the physical
1620 * port is treated as @vport 0.
1621 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001622void
1623lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001624{
James Smart92d7f7b2007-06-17 19:56:38 -05001625 del_timer_sync(&vport->els_tmofunc);
1626 del_timer_sync(&vport->fc_fdmitmo);
1627 lpfc_can_disctmo(vport);
1628 return;
dea31012005-04-17 16:05:31 -05001629}
1630
James Smarte59058c2008-08-24 21:49:00 -04001631/**
1632 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1633 * @phba: pointer to lpfc hba data structure.
1634 *
1635 * This routine stops all the timers associated with a HBA. This function is
1636 * invoked before either putting a HBA offline or unloading the driver.
1637 **/
James Smart2e0fef82007-06-17 19:56:36 -05001638static void
James Smart92d7f7b2007-06-17 19:56:38 -05001639lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001640{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001641 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001642 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001643 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001644 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001645 phba->hb_outstanding = 0;
1646 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001647 return;
dea31012005-04-17 16:05:31 -05001648}
1649
James Smarte59058c2008-08-24 21:49:00 -04001650/**
1651 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1652 * @phba: pointer to lpfc hba data structure.
1653 *
1654 * This routine marks a HBA's management interface as blocked. Once the HBA's
1655 * management interface is marked as blocked, all the user space access to
1656 * the HBA, whether they are from sysfs interface or libdfc interface will
1657 * all be blocked. The HBA is set to block the management interface when the
1658 * driver prepares the HBA interface for online or offline.
1659 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001660static void
1661lpfc_block_mgmt_io(struct lpfc_hba * phba)
1662{
1663 unsigned long iflag;
1664
1665 spin_lock_irqsave(&phba->hbalock, iflag);
1666 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1667 spin_unlock_irqrestore(&phba->hbalock, iflag);
1668}
1669
James Smarte59058c2008-08-24 21:49:00 -04001670/**
1671 * lpfc_online: Initialize and bring a HBA online.
1672 * @phba: pointer to lpfc hba data structure.
1673 *
1674 * This routine initializes the HBA and brings a HBA online. During this
1675 * process, the management interface is blocked to prevent user space access
1676 * to the HBA interfering with the driver initialization.
1677 *
1678 * Return codes
1679 * 0 - successful
1680 * 1 - failed
1681 **/
dea31012005-04-17 16:05:31 -05001682int
James Smart2e0fef82007-06-17 19:56:36 -05001683lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001684{
James Smart2e0fef82007-06-17 19:56:36 -05001685 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001686 struct lpfc_vport **vports;
1687 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001688
dea31012005-04-17 16:05:31 -05001689 if (!phba)
1690 return 0;
1691
James Smart2e0fef82007-06-17 19:56:36 -05001692 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001693 return 0;
1694
James Smarted957682007-06-17 19:56:37 -05001695 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001696 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001697
James Smart46fa3112007-04-25 09:51:45 -04001698 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001699
James Smart46fa3112007-04-25 09:51:45 -04001700 if (!lpfc_sli_queue_setup(phba)) {
1701 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001702 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001703 }
1704
1705 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1706 lpfc_unblock_mgmt_io(phba);
1707 return 1;
1708 }
dea31012005-04-17 16:05:31 -05001709
James Smart549e55c2007-08-02 11:09:51 -04001710 vports = lpfc_create_vport_work_array(phba);
1711 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001712 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001713 struct Scsi_Host *shost;
1714 shost = lpfc_shost_from_vport(vports[i]);
1715 spin_lock_irq(shost->host_lock);
1716 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1717 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1718 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1719 spin_unlock_irq(shost->host_lock);
1720 }
James Smart09372822008-01-11 01:52:54 -05001721 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001722
James Smart46fa3112007-04-25 09:51:45 -04001723 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001724 return 0;
1725}
1726
James Smarte59058c2008-08-24 21:49:00 -04001727/**
1728 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1729 * @phba: pointer to lpfc hba data structure.
1730 *
1731 * This routine marks a HBA's management interface as not blocked. Once the
1732 * HBA's management interface is marked as not blocked, all the user space
1733 * access to the HBA, whether they are from sysfs interface or libdfc
1734 * interface will be allowed. The HBA is set to block the management interface
1735 * when the driver prepares the HBA interface for online or offline and then
1736 * set to unblock the management interface afterwards.
1737 **/
James Smart46fa3112007-04-25 09:51:45 -04001738void
James Smart46fa3112007-04-25 09:51:45 -04001739lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1740{
1741 unsigned long iflag;
1742
James Smart2e0fef82007-06-17 19:56:36 -05001743 spin_lock_irqsave(&phba->hbalock, iflag);
1744 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1745 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001746}
1747
James Smarte59058c2008-08-24 21:49:00 -04001748/**
1749 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1750 * @phba: pointer to lpfc hba data structure.
1751 *
1752 * This routine is invoked to prepare a HBA to be brought offline. It performs
1753 * unregistration login to all the nodes on all vports and flushes the mailbox
1754 * queue to make it ready to be brought offline.
1755 **/
James Smart46fa3112007-04-25 09:51:45 -04001756void
1757lpfc_offline_prep(struct lpfc_hba * phba)
1758{
James Smart2e0fef82007-06-17 19:56:36 -05001759 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001760 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001761 struct lpfc_vport **vports;
1762 int i;
dea31012005-04-17 16:05:31 -05001763
James Smart2e0fef82007-06-17 19:56:36 -05001764 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001765 return;
dea31012005-04-17 16:05:31 -05001766
James Smart46fa3112007-04-25 09:51:45 -04001767 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001768
1769 lpfc_linkdown(phba);
1770
James Smart87af33f2007-10-27 13:37:43 -04001771 /* Issue an unreg_login to all nodes on all vports */
1772 vports = lpfc_create_vport_work_array(phba);
1773 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001774 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001775 struct Scsi_Host *shost;
1776
James Smarta8adb832007-10-27 13:37:53 -04001777 if (vports[i]->load_flag & FC_UNLOADING)
1778 continue;
James Smart87af33f2007-10-27 13:37:43 -04001779 shost = lpfc_shost_from_vport(vports[i]);
1780 list_for_each_entry_safe(ndlp, next_ndlp,
1781 &vports[i]->fc_nodes,
1782 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001783 if (!NLP_CHK_NODE_ACT(ndlp))
1784 continue;
James Smart87af33f2007-10-27 13:37:43 -04001785 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1786 continue;
1787 if (ndlp->nlp_type & NLP_FABRIC) {
1788 lpfc_disc_state_machine(vports[i], ndlp,
1789 NULL, NLP_EVT_DEVICE_RECOVERY);
1790 lpfc_disc_state_machine(vports[i], ndlp,
1791 NULL, NLP_EVT_DEVICE_RM);
1792 }
1793 spin_lock_irq(shost->host_lock);
1794 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1795 spin_unlock_irq(shost->host_lock);
1796 lpfc_unreg_rpi(vports[i], ndlp);
1797 }
1798 }
1799 }
James Smart09372822008-01-11 01:52:54 -05001800 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001801
James Smart46fa3112007-04-25 09:51:45 -04001802 lpfc_sli_flush_mbox_queue(phba);
1803}
1804
James Smarte59058c2008-08-24 21:49:00 -04001805/**
1806 * lpfc_offline: Bring a HBA offline.
1807 * @phba: pointer to lpfc hba data structure.
1808 *
1809 * This routine actually brings a HBA offline. It stops all the timers
1810 * associated with the HBA, brings down the SLI layer, and eventually
1811 * marks the HBA as in offline state for the upper layer protocol.
1812 **/
James Smart46fa3112007-04-25 09:51:45 -04001813void
James Smart2e0fef82007-06-17 19:56:36 -05001814lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001815{
James Smart549e55c2007-08-02 11:09:51 -04001816 struct Scsi_Host *shost;
1817 struct lpfc_vport **vports;
1818 int i;
James Smart46fa3112007-04-25 09:51:45 -04001819
James Smart549e55c2007-08-02 11:09:51 -04001820 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001821 return;
James Smart688a8862006-07-06 15:49:56 -04001822
dea31012005-04-17 16:05:31 -05001823 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001824 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001825 vports = lpfc_create_vport_work_array(phba);
1826 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001827 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001828 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001829 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001830 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001831 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001832 /* Bring down the SLI Layer and cleanup. The HBA is offline
1833 now. */
1834 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001835 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001836 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001837 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001838 vports = lpfc_create_vport_work_array(phba);
1839 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001840 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001841 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001842 spin_lock_irq(shost->host_lock);
1843 vports[i]->work_port_events = 0;
1844 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1845 spin_unlock_irq(shost->host_lock);
1846 }
James Smart09372822008-01-11 01:52:54 -05001847 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001848}
1849
James Smarte59058c2008-08-24 21:49:00 -04001850/**
1851 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1852 * @phba: pointer to lpfc hba data structure.
1853 *
1854 * This routine is to free all the SCSI buffers and IOCBs from the driver
1855 * list back to kernel. It is called from lpfc_pci_remove_one to free
1856 * the internal resources before the device is removed from the system.
1857 *
1858 * Return codes
1859 * 0 - successful (for now, it always returns 0)
1860 **/
dea31012005-04-17 16:05:31 -05001861static int
James Smart2e0fef82007-06-17 19:56:36 -05001862lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001863{
1864 struct lpfc_scsi_buf *sb, *sb_next;
1865 struct lpfc_iocbq *io, *io_next;
1866
James Smart2e0fef82007-06-17 19:56:36 -05001867 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001868 /* Release all the lpfc_scsi_bufs maintained by this host. */
1869 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1870 list_del(&sb->list);
1871 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001872 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001873 kfree(sb);
1874 phba->total_scsi_bufs--;
1875 }
1876
1877 /* Release all the lpfc_iocbq entries maintained by this host. */
1878 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1879 list_del(&io->list);
1880 kfree(io);
1881 phba->total_iocbq_bufs--;
1882 }
1883
James Smart2e0fef82007-06-17 19:56:36 -05001884 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001885
1886 return 0;
1887}
1888
James Smarte59058c2008-08-24 21:49:00 -04001889/**
1890 * lpfc_create_port: Create an FC port.
1891 * @phba: pointer to lpfc hba data structure.
1892 * @instance: a unique integer ID to this FC port.
1893 * @dev: pointer to the device data structure.
1894 *
1895 * This routine creates a FC port for the upper layer protocol. The FC port
1896 * can be created on top of either a physical port or a virtual port provided
1897 * by the HBA. This routine also allocates a SCSI host data structure (shost)
1898 * and associates the FC port created before adding the shost into the SCSI
1899 * layer.
1900 *
1901 * Return codes
1902 * @vport - pointer to the virtual N_Port data structure.
1903 * NULL - port create failed.
1904 **/
James Smart2e0fef82007-06-17 19:56:36 -05001905struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001906lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001907{
James Smart2e0fef82007-06-17 19:56:36 -05001908 struct lpfc_vport *vport;
1909 struct Scsi_Host *shost;
1910 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001911
James Smart3de2a652007-08-02 11:09:59 -04001912 if (dev != &phba->pcidev->dev)
1913 shost = scsi_host_alloc(&lpfc_vport_template,
1914 sizeof(struct lpfc_vport));
1915 else
1916 shost = scsi_host_alloc(&lpfc_template,
1917 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (!shost)
1919 goto out;
James Smart47a86172007-04-25 09:53:22 -04001920
James Smart2e0fef82007-06-17 19:56:36 -05001921 vport = (struct lpfc_vport *) shost->hostdata;
1922 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05001923 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001924 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05001925 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04001926
James Smart3de2a652007-08-02 11:09:59 -04001927 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001928 shost->unique_id = instance;
1929 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001930 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001931 shost->this_id = -1;
1932 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001933 /*
James Smart2e0fef82007-06-17 19:56:36 -05001934 * Set initial can_queue value since 0 is no longer supported and
1935 * scsi_add_host will fail. This will be adjusted later based on the
1936 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001937 */
James Smart2e0fef82007-06-17 19:56:36 -05001938 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001939 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001940 shost->transportt = lpfc_vport_transport_template;
1941 vport->port_type = LPFC_NPIV_PORT;
1942 } else {
1943 shost->transportt = lpfc_transport_template;
1944 vport->port_type = LPFC_PHYSICAL_PORT;
1945 }
James Smart47a86172007-04-25 09:53:22 -04001946
James Smart2e0fef82007-06-17 19:56:36 -05001947 /* Initialize all internally managed lists. */
1948 INIT_LIST_HEAD(&vport->fc_nodes);
1949 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001950
James Smart2e0fef82007-06-17 19:56:36 -05001951 init_timer(&vport->fc_disctmo);
1952 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001953 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001954
James Smart2e0fef82007-06-17 19:56:36 -05001955 init_timer(&vport->fc_fdmitmo);
1956 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001957 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001958
James Smart2e0fef82007-06-17 19:56:36 -05001959 init_timer(&vport->els_tmofunc);
1960 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001961 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001962
James Smart3de2a652007-08-02 11:09:59 -04001963 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001964 if (error)
1965 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001966
James Smart549e55c2007-08-02 11:09:51 -04001967 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001968 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001969 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001970 return vport;
James Smart47a86172007-04-25 09:53:22 -04001971
James Smart2e0fef82007-06-17 19:56:36 -05001972out_put_shost:
1973 scsi_host_put(shost);
1974out:
1975 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001976}
1977
James Smarte59058c2008-08-24 21:49:00 -04001978/**
1979 * destroy_port: Destroy an FC port.
1980 * @vport: pointer to an lpfc virtual N_Port data structure.
1981 *
1982 * This routine destroys a FC port from the upper layer protocol. All the
1983 * resources associated with the port are released.
1984 **/
James Smart2e0fef82007-06-17 19:56:36 -05001985void
1986destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001987{
James Smart92d7f7b2007-06-17 19:56:38 -05001988 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1989 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001990
James Smart92d7f7b2007-06-17 19:56:38 -05001991 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001992
James Smart858c9f62007-06-17 19:56:39 -05001993 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001994 fc_remove_host(shost);
1995 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001996
James Smart92d7f7b2007-06-17 19:56:38 -05001997 spin_lock_irq(&phba->hbalock);
1998 list_del_init(&vport->listentry);
1999 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002000
James Smart92d7f7b2007-06-17 19:56:38 -05002001 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002002 return;
James Smart47a86172007-04-25 09:53:22 -04002003}
2004
James Smarte59058c2008-08-24 21:49:00 -04002005/**
2006 * lpfc_get_instance: Get a unique integer ID.
2007 *
2008 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2009 * uses the kernel idr facility to perform the task.
2010 *
2011 * Return codes:
2012 * instance - a unique integer ID allocated as the new instance.
2013 * -1 - lpfc get instance failed.
2014 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002015int
2016lpfc_get_instance(void)
2017{
2018 int instance = 0;
2019
2020 /* Assign an unused number */
2021 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2022 return -1;
2023 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2024 return -1;
2025 return instance;
2026}
2027
James Smarte59058c2008-08-24 21:49:00 -04002028/**
2029 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2030 * @shost: pointer to SCSI host data structure.
2031 * @time: elapsed time of the scan in jiffies.
2032 *
2033 * This routine is called by the SCSI layer with a SCSI host to determine
2034 * whether the scan host is finished.
2035 *
2036 * Note: there is no scan_start function as adapter initialization will have
2037 * asynchronously kicked off the link initialization.
2038 *
2039 * Return codes
2040 * 0 - SCSI host scan is not over yet.
2041 * 1 - SCSI host scan is over.
2042 **/
James Smart47a86172007-04-25 09:53:22 -04002043int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2044{
James Smart2e0fef82007-06-17 19:56:36 -05002045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2046 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002047 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002048
James Smart858c9f62007-06-17 19:56:39 -05002049 spin_lock_irq(shost->host_lock);
2050
James Smart51ef4c22007-08-02 11:10:31 -04002051 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002052 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002053 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002054 }
James Smart2e0fef82007-06-17 19:56:36 -05002055 if (time >= 30 * HZ) {
2056 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002057 "0461 Scanning longer than 30 "
2058 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002059 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002060 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002061 }
2062 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2063 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002064 "0465 Link down longer than 15 "
2065 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002066 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002067 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002068 }
2069
James Smart2e0fef82007-06-17 19:56:36 -05002070 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002071 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002072 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002073 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002074 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002075 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002076 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002077 goto finished;
2078
2079 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002080
2081finished:
James Smart858c9f62007-06-17 19:56:39 -05002082 spin_unlock_irq(shost->host_lock);
2083 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002084}
2085
James Smarte59058c2008-08-24 21:49:00 -04002086/**
2087 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2088 * @shost: pointer to SCSI host data structure.
2089 *
2090 * This routine initializes a given SCSI host attributes on a FC port. The
2091 * SCSI host can be either on top of a physical port or a virtual port.
2092 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002093void lpfc_host_attrib_init(struct Scsi_Host *shost)
2094{
2095 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2096 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002097 /*
James Smart2e0fef82007-06-17 19:56:36 -05002098 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002099 */
2100
James Smart2e0fef82007-06-17 19:56:36 -05002101 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2102 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002103 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2104
2105 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002106 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002107 fc_host_supported_fc4s(shost)[2] = 1;
2108 fc_host_supported_fc4s(shost)[7] = 1;
2109
James Smart92d7f7b2007-06-17 19:56:38 -05002110 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2111 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002112
2113 fc_host_supported_speeds(shost) = 0;
2114 if (phba->lmt & LMT_10Gb)
2115 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002116 if (phba->lmt & LMT_8Gb)
2117 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002118 if (phba->lmt & LMT_4Gb)
2119 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2120 if (phba->lmt & LMT_2Gb)
2121 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2122 if (phba->lmt & LMT_1Gb)
2123 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2124
2125 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002126 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2127 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002128
2129 /* This value is also unchanging */
2130 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002131 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002132 fc_host_active_fc4s(shost)[2] = 1;
2133 fc_host_active_fc4s(shost)[7] = 1;
2134
James Smart92d7f7b2007-06-17 19:56:38 -05002135 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002136 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002137 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002138 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002139}
dea31012005-04-17 16:05:31 -05002140
James Smarte59058c2008-08-24 21:49:00 -04002141/**
2142 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2143 * @phba: pointer to lpfc hba data structure.
2144 *
2145 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2146 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2147 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2148 * on the current availability of PCI vector resources. The device driver is
2149 * responsible for calling the individual request_irq() to register each MSI-X
2150 * vector with a interrupt handler, which is done in this function. Note that
2151 * later when device is unloading, the driver should always call free_irq()
2152 * on all MSI-X vectors it has done request_irq() on before calling
2153 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2154 * will be left with MSI-X enabled and leaks its vectors.
2155 *
2156 * Return codes
2157 * 0 - sucessful
2158 * other values - error
2159 **/
James Smartdb2378e2008-02-08 18:49:51 -05002160static int
2161lpfc_enable_msix(struct lpfc_hba *phba)
2162{
2163 int error;
2164
2165 phba->msix_entries[0].entry = 0;
2166 phba->msix_entries[0].vector = 0;
2167
2168 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
2169 ARRAY_SIZE(phba->msix_entries));
2170 if (error) {
2171 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2172 "0420 Enable MSI-X failed (%d), continuing "
2173 "with MSI\n", error);
2174 pci_disable_msix(phba->pcidev);
2175 return error;
2176 }
2177
2178 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
2179 LPFC_DRIVER_NAME, phba);
2180 if (error) {
2181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2182 "0421 MSI-X request_irq failed (%d), "
2183 "continuing with MSI\n", error);
2184 pci_disable_msix(phba->pcidev);
2185 }
2186 return error;
2187}
2188
James Smarte59058c2008-08-24 21:49:00 -04002189/**
2190 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2191 * @phba: pointer to lpfc hba data structure.
2192 *
2193 * This routine is invoked to release the MSI-X vectors and then disable the
2194 * MSI-X interrupt mode.
2195 **/
James Smartdb2378e2008-02-08 18:49:51 -05002196static void
2197lpfc_disable_msix(struct lpfc_hba *phba)
2198{
2199 free_irq(phba->msix_entries[0].vector, phba);
2200 pci_disable_msix(phba->pcidev);
2201}
2202
James Smarte59058c2008-08-24 21:49:00 -04002203/**
2204 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2205 * @pdev: pointer to PCI device
2206 * @pid: pointer to PCI device identifier
2207 *
2208 * This routine is to be registered to the kernel's PCI subsystem. When an
2209 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2210 * PCI device-specific information of the device and driver to see if the
2211 * driver state that it can support this kind of device. If the match is
2212 * successful, the driver core invokes this routine. If this routine
2213 * determines it can claim the HBA, it does all the initialization that it
2214 * needs to do to handle the HBA properly.
2215 *
2216 * Return code
2217 * 0 - driver can claim the device
2218 * negative value - driver can not claim the device
2219 **/
dea31012005-04-17 16:05:31 -05002220static int __devinit
2221lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2222{
James Smart2e0fef82007-06-17 19:56:36 -05002223 struct lpfc_vport *vport = NULL;
2224 struct lpfc_hba *phba;
2225 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002226 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002227 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04002228 void *ptr;
dea31012005-04-17 16:05:31 -05002229 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04002230 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04002231 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05002232 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002233 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05002234
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01002235 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05002236 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002237 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05002238 goto out_disable_device;
2239
James Smart2e0fef82007-06-17 19:56:36 -05002240 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2241 if (!phba)
dea31012005-04-17 16:05:31 -05002242 goto out_release_regions;
2243
James Smart2e0fef82007-06-17 19:56:36 -05002244 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002245
James Smarte47c9092008-02-08 18:49:26 -05002246 /* Initialize ndlp management spinlock */
2247 spin_lock_init(&phba->ndlp_lock);
2248
dea31012005-04-17 16:05:31 -05002249 phba->pcidev = pdev;
2250
2251 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05002252 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05002253 goto out_free_phba;
dea31012005-04-17 16:05:31 -05002254
James Smart2e0fef82007-06-17 19:56:36 -05002255 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05002256 /*
2257 * Get all the module params for configuring this host and then
2258 * establish the host.
2259 */
2260 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002261 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002262
2263 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05002264 init_timer(&phba->hb_tmofunc);
2265 phba->hb_tmofunc.function = lpfc_hb_timeout;
2266 phba->hb_tmofunc.data = (unsigned long)phba;
2267
dea31012005-04-17 16:05:31 -05002268 psli = &phba->sli;
2269 init_timer(&psli->mbox_tmo);
2270 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002271 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002272 init_timer(&phba->fcp_poll_timer);
2273 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002274 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002275 init_timer(&phba->fabric_block_timer);
2276 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2277 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002278
dea31012005-04-17 16:05:31 -05002279 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002280 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002281
2282 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2283 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2284 goto out_idr_remove;
2285
2286 /*
2287 * Get the bus address of Bar0 and Bar2 and the number of bytes
2288 * required by each mapping.
2289 */
2290 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2291 bar0map_len = pci_resource_len(phba->pcidev, 0);
2292
2293 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2294 bar2map_len = pci_resource_len(phba->pcidev, 2);
2295
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002296 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002297 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002298 if (!phba->slim_memmap_p) {
2299 error = -ENODEV;
2300 dev_printk(KERN_ERR, &pdev->dev,
2301 "ioremap failed for SLIM memory.\n");
2302 goto out_idr_remove;
2303 }
2304
2305 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002306 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002307 if (!phba->ctrl_regs_memmap_p) {
2308 error = -ENODEV;
2309 dev_printk(KERN_ERR, &pdev->dev,
2310 "ioremap failed for HBA control registers.\n");
2311 goto out_iounmap_slim;
2312 }
dea31012005-04-17 16:05:31 -05002313
2314 /* Allocate memory for SLI-2 structures */
James Smart34b02dc2008-08-24 21:49:55 -04002315 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2316 SLI2_SLIM_SIZE,
2317 &phba->slim2p.phys,
2318 GFP_KERNEL);
2319 if (!phba->slim2p.virt)
dea31012005-04-17 16:05:31 -05002320 goto out_iounmap;
2321
James Smart34b02dc2008-08-24 21:49:55 -04002322 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
2323 phba->mbox = phba->slim2p.virt;
2324 phba->pcb = (phba->slim2p.virt + sizeof(MAILBOX_t));
2325 phba->IOCBs = (phba->slim2p.virt + sizeof(MAILBOX_t) +
2326 sizeof(struct _PCB));
dea31012005-04-17 16:05:31 -05002327
James Smarted957682007-06-17 19:56:37 -05002328 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2329 lpfc_sli_hbq_size(),
2330 &phba->hbqslimp.phys,
2331 GFP_KERNEL);
2332 if (!phba->hbqslimp.virt)
2333 goto out_free_slim;
2334
James Smart51ef4c22007-08-02 11:10:31 -04002335 hbq_count = lpfc_sli_hbq_count();
2336 ptr = phba->hbqslimp.virt;
2337 for (i = 0; i < hbq_count; ++i) {
2338 phba->hbqs[i].hbq_virt = ptr;
2339 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2340 ptr += (lpfc_hbq_defs[i]->entry_count *
2341 sizeof(struct lpfc_hbq_entry));
2342 }
2343 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2344 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2345
James Smarted957682007-06-17 19:56:37 -05002346 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2347
James Smart3163f722008-02-08 18:50:25 -05002348 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2349
dea31012005-04-17 16:05:31 -05002350 /* Initialize the SLI Layer to run with lpfc HBAs. */
2351 lpfc_sli_setup(phba);
2352 lpfc_sli_queue_setup(phba);
2353
James Smart98c9ea52007-10-27 13:37:33 -04002354 retval = lpfc_mem_alloc(phba);
2355 if (retval) {
2356 error = retval;
James Smarted957682007-06-17 19:56:37 -05002357 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002358 }
dea31012005-04-17 16:05:31 -05002359
2360 /* Initialize and populate the iocb list per host. */
2361 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2362 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002363 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002364 if (iocbq_entry == NULL) {
2365 printk(KERN_ERR "%s: only allocated %d iocbs of "
2366 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002367 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002368 error = -ENOMEM;
2369 goto out_free_iocbq;
2370 }
2371
James Bottomley604a3e32005-10-29 10:28:33 -05002372 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2373 if (iotag == 0) {
2374 kfree (iocbq_entry);
2375 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2376 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002377 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002378 error = -ENOMEM;
2379 goto out_free_iocbq;
2380 }
James Smart2e0fef82007-06-17 19:56:36 -05002381
2382 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002383 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2384 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002385 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002386 }
2387
2388 /* Initialize HBA structure */
2389 phba->fc_edtov = FF_DEF_EDTOV;
2390 phba->fc_ratov = FF_DEF_RATOV;
2391 phba->fc_altov = FF_DEF_ALTOV;
2392 phba->fc_arbtov = FF_DEF_ARBTOV;
2393
2394 INIT_LIST_HEAD(&phba->work_list);
2395 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2396 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2397
James Smart5e9d9b82008-06-14 22:52:53 -04002398 /* Initialize the wait queue head for the kernel thread */
2399 init_waitqueue_head(&phba->work_waitq);
2400
dea31012005-04-17 16:05:31 -05002401 /* Startup the kernel thread for this host adapter. */
2402 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2403 "lpfc_worker_%d", phba->brd_no);
2404 if (IS_ERR(phba->worker_thread)) {
2405 error = PTR_ERR(phba->worker_thread);
2406 goto out_free_iocbq;
2407 }
2408
dea31012005-04-17 16:05:31 -05002409 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002410 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002411 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2412
James Smart92d7f7b2007-06-17 19:56:38 -05002413 /* Initialize list of fabric iocbs */
2414 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2415
James Smart0ff10d42008-01-11 01:52:36 -05002416 /* Initialize list to save ELS buffers */
2417 INIT_LIST_HEAD(&phba->elsbuf);
2418
James Smart3de2a652007-08-02 11:09:59 -04002419 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002420 if (!vport)
2421 goto out_kthread_stop;
2422
2423 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002424 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002425 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002426
James Smart92d7f7b2007-06-17 19:56:38 -05002427 pci_set_drvdata(pdev, shost);
James Smartdb2378e2008-02-08 18:49:51 -05002428 phba->intr_type = NONE;
dea31012005-04-17 16:05:31 -05002429
James Smartdb2378e2008-02-08 18:49:51 -05002430 if (phba->cfg_use_msi == 2) {
2431 error = lpfc_enable_msix(phba);
2432 if (!error)
2433 phba->intr_type = MSIX;
2434 }
2435
2436 /* Fallback to MSI if MSI-X initialization failed */
2437 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
James Smart98c9ea52007-10-27 13:37:33 -04002438 retval = pci_enable_msi(phba->pcidev);
2439 if (!retval)
James Smartdb2378e2008-02-08 18:49:51 -05002440 phba->intr_type = MSI;
James Smart51ef4c22007-08-02 11:10:31 -04002441 else
James Smarte8b62012007-08-02 11:10:09 -04002442 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2443 "0452 Enable MSI failed, continuing "
2444 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002445 }
2446
James Smartdb2378e2008-02-08 18:49:51 -05002447 /* MSI-X is the only case the doesn't need to call request_irq */
2448 if (phba->intr_type != MSIX) {
2449 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2450 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2451 if (retval) {
2452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2453 "interrupt handler failed\n");
2454 error = retval;
2455 goto out_disable_msi;
2456 } else if (phba->intr_type != MSI)
2457 phba->intr_type = INTx;
dea31012005-04-17 16:05:31 -05002458 }
dea31012005-04-17 16:05:31 -05002459
James Smart2e0fef82007-06-17 19:56:36 -05002460 phba->MBslimaddr = phba->slim_memmap_p;
2461 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2462 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2463 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2464 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2465
James Smart98c9ea52007-10-27 13:37:33 -04002466 if (lpfc_alloc_sysfs_attr(vport)) {
2467 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002468 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002469 }
dea31012005-04-17 16:05:31 -05002470
James Smart98c9ea52007-10-27 13:37:33 -04002471 if (lpfc_sli_hba_setup(phba)) {
2472 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002473 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002474 }
James Smart858c9f62007-06-17 19:56:39 -05002475
2476 /*
2477 * hba setup may have changed the hba_queue_depth so we need to adjust
2478 * the value of can_queue.
2479 */
2480 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2481
2482 lpfc_host_attrib_init(shost);
2483
James Smart2e0fef82007-06-17 19:56:36 -05002484 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2485 spin_lock_irq(shost->host_lock);
2486 lpfc_poll_start_timer(phba);
2487 spin_unlock_irq(shost->host_lock);
2488 }
James Smart8f6d98d2006-08-01 07:34:00 -04002489
James Smart858c9f62007-06-17 19:56:39 -05002490 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002491
dea31012005-04-17 16:05:31 -05002492 return 0;
2493
James Smart858c9f62007-06-17 19:56:39 -05002494out_remove_device:
2495 lpfc_free_sysfs_attr(vport);
2496 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002497 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002498 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002499out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002500 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002501 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002502
2503 if (phba->intr_type == MSIX)
2504 lpfc_disable_msix(phba);
2505 else
2506 free_irq(phba->pcidev->irq, phba);
2507
James Smart92d7f7b2007-06-17 19:56:38 -05002508out_disable_msi:
James Smartdb2378e2008-02-08 18:49:51 -05002509 if (phba->intr_type == MSI)
James Smart51ef4c22007-08-02 11:10:31 -04002510 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002511 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002512out_kthread_stop:
2513 kthread_stop(phba->worker_thread);
2514out_free_iocbq:
2515 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2516 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002517 kfree(iocbq_entry);
2518 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002519 }
2520 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002521out_free_hbqslimp:
James Smart34b02dc2008-08-24 21:49:55 -04002522 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2523 phba->hbqslimp.virt, phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002524out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04002525 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2526 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05002527out_iounmap:
2528 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002529out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002530 iounmap(phba->slim_memmap_p);
2531out_idr_remove:
2532 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002533out_free_phba:
2534 kfree(phba);
dea31012005-04-17 16:05:31 -05002535out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002536 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002537out_disable_device:
2538 pci_disable_device(pdev);
2539out:
James Smartdefbcf12006-04-16 22:26:50 -04002540 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002541 if (shost)
2542 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002543 return error;
2544}
2545
James Smarte59058c2008-08-24 21:49:00 -04002546/**
2547 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2548 * @pdev: pointer to PCI device
2549 *
2550 * This routine is to be registered to the kernel's PCI subsystem. When an
2551 * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup
2552 * for the HBA device to be removed from the PCI subsystem properly.
2553 **/
dea31012005-04-17 16:05:31 -05002554static void __devexit
2555lpfc_pci_remove_one(struct pci_dev *pdev)
2556{
James Smart2e0fef82007-06-17 19:56:36 -05002557 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2558 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2559 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002560 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2561
James Smart549e55c2007-08-02 11:09:51 -04002562 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002563 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002564 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002565
James Smart858c9f62007-06-17 19:56:39 -05002566 kfree(vport->vname);
2567 lpfc_free_sysfs_attr(vport);
2568
James Smart09372822008-01-11 01:52:54 -05002569 kthread_stop(phba->worker_thread);
2570
James Smart858c9f62007-06-17 19:56:39 -05002571 fc_remove_host(shost);
2572 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002573 lpfc_cleanup(vport);
2574
James Smart2e0fef82007-06-17 19:56:36 -05002575 /*
2576 * Bring down the SLI Layer. This step disable all interrupts,
2577 * clears the rings, discards all mailbox commands, and resets
2578 * the HBA.
2579 */
2580 lpfc_sli_hba_down(phba);
2581 lpfc_sli_brdrestart(phba);
2582
James Smart92d7f7b2007-06-17 19:56:38 -05002583 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002584 spin_lock_irq(&phba->hbalock);
2585 list_del_init(&vport->listentry);
2586 spin_unlock_irq(&phba->hbalock);
2587
James Smart858c9f62007-06-17 19:56:39 -05002588 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002589
James Smartdb2378e2008-02-08 18:49:51 -05002590 if (phba->intr_type == MSIX)
2591 lpfc_disable_msix(phba);
2592 else {
2593 free_irq(phba->pcidev->irq, phba);
2594 if (phba->intr_type == MSI)
2595 pci_disable_msi(phba->pcidev);
2596 }
dea31012005-04-17 16:05:31 -05002597
2598 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002599 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002600
2601 /*
2602 * Call scsi_free before mem_free since scsi bufs are released to their
2603 * corresponding pools here.
2604 */
2605 lpfc_scsi_free(phba);
2606 lpfc_mem_free(phba);
2607
James Smart34b02dc2008-08-24 21:49:55 -04002608 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2609 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05002610
James Smart2e0fef82007-06-17 19:56:36 -05002611 /* Free resources associated with SLI2 interface */
2612 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04002613 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05002614
2615 /* unmap adapter SLIM and Control Registers */
2616 iounmap(phba->ctrl_regs_memmap_p);
2617 iounmap(phba->slim_memmap_p);
2618
2619 idr_remove(&lpfc_hba_index, phba->brd_no);
2620
2621 kfree(phba);
2622
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002623 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002624 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002625}
2626
Linas Vepstas8d63f372007-02-14 14:28:36 -06002627/**
James Smarte59058c2008-08-24 21:49:00 -04002628 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
2629 * @pdev: pointer to PCI device.
2630 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002631 *
James Smarte59058c2008-08-24 21:49:00 -04002632 * This routine is registered to the PCI subsystem for error handling. This
2633 * function is called by the PCI subsystem after a PCI bus error affecting
2634 * this device has been detected. When this function is invoked, it will
2635 * need to stop all the I/Os and interrupt(s) to the device. Once that is
2636 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
2637 * perform proper recovery as desired.
2638 *
2639 * Return codes
2640 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
2641 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2642 **/
Linas Vepstas8d63f372007-02-14 14:28:36 -06002643static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2644 pci_channel_state_t state)
2645{
James Smart51ef4c22007-08-02 11:10:31 -04002646 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2647 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002648 struct lpfc_sli *psli = &phba->sli;
2649 struct lpfc_sli_ring *pring;
2650
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002651 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002652 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002653
Linas Vepstas8d63f372007-02-14 14:28:36 -06002654 pci_disable_device(pdev);
2655 /*
2656 * There may be I/Os dropped by the firmware.
2657 * Error iocb (I/O) on txcmplq and let the SCSI layer
2658 * retry it after re-establishing link.
2659 */
2660 pring = &psli->ring[psli->fcp_ring];
2661 lpfc_sli_abort_iocb_ring(phba, pring);
2662
James Smartdb2378e2008-02-08 18:49:51 -05002663 if (phba->intr_type == MSIX)
2664 lpfc_disable_msix(phba);
2665 else {
2666 free_irq(phba->pcidev->irq, phba);
2667 if (phba->intr_type == MSI)
2668 pci_disable_msi(phba->pcidev);
2669 }
James Smart51ef4c22007-08-02 11:10:31 -04002670
Linas Vepstas8d63f372007-02-14 14:28:36 -06002671 /* Request a slot reset. */
2672 return PCI_ERS_RESULT_NEED_RESET;
2673}
2674
2675/**
James Smarte59058c2008-08-24 21:49:00 -04002676 * lpfc_io_slot_reset: Restart a PCI device from scratch.
2677 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002678 *
James Smarte59058c2008-08-24 21:49:00 -04002679 * This routine is registered to the PCI subsystem for error handling. This is
2680 * called after PCI bus has been reset to restart the PCI card from scratch,
2681 * as if from a cold-boot. During the PCI subsystem error recovery, after the
2682 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
2683 * proper error recovery and then call this routine before calling the .resume
2684 * method to recover the device. This function will initialize the HBA device,
2685 * enable the interrupt, but it will just put the HBA to offline state without
2686 * passing any I/O traffic.
2687 *
2688 * Return codes
2689 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
2690 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06002691 */
2692static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2693{
James Smart51ef4c22007-08-02 11:10:31 -04002694 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2695 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002696 struct lpfc_sli *psli = &phba->sli;
James Smart9b379602008-04-07 10:16:00 -04002697 int error, retval;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002698
2699 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002700 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002701 printk(KERN_ERR "lpfc: Cannot re-enable "
2702 "PCI device after reset.\n");
2703 return PCI_ERS_RESULT_DISCONNECT;
2704 }
2705
2706 pci_set_master(pdev);
2707
James Smart92d7f7b2007-06-17 19:56:38 -05002708 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002709 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002710 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002711
James Smart9b379602008-04-07 10:16:00 -04002712 /* Enable configured interrupt method */
2713 phba->intr_type = NONE;
2714 if (phba->cfg_use_msi == 2) {
2715 error = lpfc_enable_msix(phba);
2716 if (!error)
2717 phba->intr_type = MSIX;
2718 }
2719
2720 /* Fallback to MSI if MSI-X initialization failed */
2721 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2722 retval = pci_enable_msi(phba->pcidev);
2723 if (!retval)
2724 phba->intr_type = MSI;
2725 else
2726 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2727 "0470 Enable MSI failed, continuing "
2728 "with IRQ\n");
2729 }
2730
2731 /* MSI-X is the only case the doesn't need to call request_irq */
2732 if (phba->intr_type != MSIX) {
2733 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2734 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2735 if (retval) {
2736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2737 "0471 Enable interrupt handler "
2738 "failed\n");
2739 } else if (phba->intr_type != MSI)
2740 phba->intr_type = INTx;
2741 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06002742
2743 /* Take device offline; this will perform cleanup */
2744 lpfc_offline(phba);
2745 lpfc_sli_brdrestart(phba);
2746
2747 return PCI_ERS_RESULT_RECOVERED;
2748}
2749
2750/**
James Smarte59058c2008-08-24 21:49:00 -04002751 * lpfc_io_resume: Resume PCI I/O operation.
2752 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06002753 *
James Smarte59058c2008-08-24 21:49:00 -04002754 * This routine is registered to the PCI subsystem for error handling. It is
2755 * called when kernel error recovery tells the lpfc driver that it is ok to
2756 * resume normal PCI operation after PCI bus error recovery. After this call,
2757 * traffic can start to flow from this device again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002758 */
2759static void lpfc_io_resume(struct pci_dev *pdev)
2760{
James Smart51ef4c22007-08-02 11:10:31 -04002761 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2762 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002763
James Smart58da1ff2008-04-07 10:15:56 -04002764 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002765}
2766
dea31012005-04-17 16:05:31 -05002767static struct pci_device_id lpfc_id_table[] = {
2768 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2769 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002770 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2771 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002772 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2773 PCI_ANY_ID, PCI_ANY_ID, },
2774 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2775 PCI_ANY_ID, PCI_ANY_ID, },
2776 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2777 PCI_ANY_ID, PCI_ANY_ID, },
2778 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2779 PCI_ANY_ID, PCI_ANY_ID, },
2780 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2781 PCI_ANY_ID, PCI_ANY_ID, },
2782 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2783 PCI_ANY_ID, PCI_ANY_ID, },
2784 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2785 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002786 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2787 PCI_ANY_ID, PCI_ANY_ID, },
2788 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2789 PCI_ANY_ID, PCI_ANY_ID, },
2790 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2791 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002792 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2793 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002794 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2795 PCI_ANY_ID, PCI_ANY_ID, },
2796 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2797 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002798 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2799 PCI_ANY_ID, PCI_ANY_ID, },
2800 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2801 PCI_ANY_ID, PCI_ANY_ID, },
2802 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2803 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002804 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2805 PCI_ANY_ID, PCI_ANY_ID, },
2806 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2807 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002808 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2809 PCI_ANY_ID, PCI_ANY_ID, },
2810 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2811 PCI_ANY_ID, PCI_ANY_ID, },
2812 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2813 PCI_ANY_ID, PCI_ANY_ID, },
2814 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2815 PCI_ANY_ID, PCI_ANY_ID, },
2816 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2817 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002818 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2819 PCI_ANY_ID, PCI_ANY_ID, },
2820 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2821 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002822 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2823 PCI_ANY_ID, PCI_ANY_ID, },
2824 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2825 PCI_ANY_ID, PCI_ANY_ID, },
2826 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2827 PCI_ANY_ID, PCI_ANY_ID, },
2828 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2829 PCI_ANY_ID, PCI_ANY_ID, },
2830 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2831 PCI_ANY_ID, PCI_ANY_ID, },
2832 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2833 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002834 { 0 }
2835};
2836
2837MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2838
Linas Vepstas8d63f372007-02-14 14:28:36 -06002839static struct pci_error_handlers lpfc_err_handler = {
2840 .error_detected = lpfc_io_error_detected,
2841 .slot_reset = lpfc_io_slot_reset,
2842 .resume = lpfc_io_resume,
2843};
2844
dea31012005-04-17 16:05:31 -05002845static struct pci_driver lpfc_driver = {
2846 .name = LPFC_DRIVER_NAME,
2847 .id_table = lpfc_id_table,
2848 .probe = lpfc_pci_probe_one,
2849 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002850 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002851};
2852
James Smarte59058c2008-08-24 21:49:00 -04002853/**
2854 * lpfc_init: lpfc module initialization routine.
2855 *
2856 * This routine is to be invoked when the lpfc module is loaded into the
2857 * kernel. The special kernel macro module_init() is used to indicate the
2858 * role of this routine to the kernel as lpfc module entry point.
2859 *
2860 * Return codes
2861 * 0 - successful
2862 * -ENOMEM - FC attach transport failed
2863 * all others - failed
2864 */
dea31012005-04-17 16:05:31 -05002865static int __init
2866lpfc_init(void)
2867{
2868 int error = 0;
2869
2870 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002871 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002872
James Smart7ee5d432007-10-27 13:37:17 -04002873 if (lpfc_enable_npiv) {
2874 lpfc_transport_functions.vport_create = lpfc_vport_create;
2875 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2876 }
dea31012005-04-17 16:05:31 -05002877 lpfc_transport_template =
2878 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002879 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002880 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002881 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002882 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002883 fc_attach_transport(&lpfc_vport_transport_functions);
2884 if (lpfc_vport_transport_template == NULL) {
2885 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002886 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002887 }
James Smart7ee5d432007-10-27 13:37:17 -04002888 }
dea31012005-04-17 16:05:31 -05002889 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002890 if (error) {
dea31012005-04-17 16:05:31 -05002891 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002892 fc_release_transport(lpfc_vport_transport_template);
2893 }
dea31012005-04-17 16:05:31 -05002894
2895 return error;
2896}
2897
James Smarte59058c2008-08-24 21:49:00 -04002898/**
2899 * lpfc_exit: lpfc module removal routine.
2900 *
2901 * This routine is invoked when the lpfc module is removed from the kernel.
2902 * The special kernel macro module_exit() is used to indicate the role of
2903 * this routine to the kernel as lpfc module exit point.
2904 */
dea31012005-04-17 16:05:31 -05002905static void __exit
2906lpfc_exit(void)
2907{
2908 pci_unregister_driver(&lpfc_driver);
2909 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002910 if (lpfc_enable_npiv)
2911 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002912}
2913
2914module_init(lpfc_init);
2915module_exit(lpfc_exit);
2916MODULE_LICENSE("GPL");
2917MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2918MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2919MODULE_VERSION("0:" LPFC_DRIVER_VERSION);