blob: 41a8c13e6950fa477a48a115aa88023f44be78ff [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 */
dea31012005-04-17 16:05:31 -0500186 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
187 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400188 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500189
190 do {
191 lpfc_dump_mem(phba, pmb, offset);
192 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
193
194 if (rc != MBX_SUCCESS) {
195 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400196 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500197 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500198 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500199 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500200 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500201 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
202 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400203 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
204 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500205 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500206 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500207 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
208 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500209
210 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500211out_free_mbox:
212 mempool_free(pmb, phba->mbox_mem_pool);
213 return 0;
214}
215
James Smarte59058c2008-08-24 21:49:00 -0400216/**
217 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
218 * @phba: pointer to lpfc hba data structure.
219 * @pmboxq: pointer to the driver internal queue element for mailbox command.
220 *
221 * This is the completion handler for driver's configuring asynchronous event
222 * mailbox command to the device. If the mailbox command returns successfully,
223 * it will set internal async event support flag to 1; otherwise, it will
224 * set internal async event support flag to 0.
225 **/
James Smart57127f12007-10-27 13:37:05 -0400226static void
227lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
228{
229 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
230 phba->temp_sensor_support = 1;
231 else
232 phba->temp_sensor_support = 0;
233 mempool_free(pmboxq, phba->mbox_mem_pool);
234 return;
235}
236
James Smarte59058c2008-08-24 21:49:00 -0400237/**
238 * lpfc_config_port_post: Perform lpfc initialization after config port.
239 * @phba: pointer to lpfc hba data structure.
240 *
241 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
242 * command call. It performs all internal resource and state setups on the
243 * port: post IOCB buffers, enable appropriate host interrupt attentions,
244 * ELS ring timers, etc.
245 *
246 * Return codes
247 * 0 - success.
248 * Any other value - error.
249 **/
dea31012005-04-17 16:05:31 -0500250int
James Smart2e0fef82007-06-17 19:56:36 -0500251lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500252{
James Smart2e0fef82007-06-17 19:56:36 -0500253 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500254 LPFC_MBOXQ_t *pmb;
255 MAILBOX_t *mb;
256 struct lpfc_dmabuf *mp;
257 struct lpfc_sli *psli = &phba->sli;
258 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500259 int i, j;
260 int rc;
dea31012005-04-17 16:05:31 -0500261
James Smart7af67052007-10-27 13:38:11 -0400262 spin_lock_irq(&phba->hbalock);
263 /*
264 * If the Config port completed correctly the HBA is not
265 * over heated any more.
266 */
267 if (phba->over_temp_state == HBA_OVER_TEMP)
268 phba->over_temp_state = HBA_NORMAL_TEMP;
269 spin_unlock_irq(&phba->hbalock);
270
dea31012005-04-17 16:05:31 -0500271 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
272 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500273 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500274 return -ENOMEM;
275 }
276 mb = &pmb->mb;
277
dea31012005-04-17 16:05:31 -0500278 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500279 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500280 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500281 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400283 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500284 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500285 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500286 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500287 mp = (struct lpfc_dmabuf *) pmb->context1;
288 mempool_free( pmb, phba->mbox_mem_pool);
289 lpfc_mbuf_free(phba, mp->virt, mp->phys);
290 kfree(mp);
291 return -EIO;
292 }
293
294 mp = (struct lpfc_dmabuf *) pmb->context1;
295
James Smart2e0fef82007-06-17 19:56:36 -0500296 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500297 lpfc_mbuf_free(phba, mp->virt, mp->phys);
298 kfree(mp);
299 pmb->context1 = NULL;
300
James Smarta12e07b2006-12-02 13:35:30 -0500301 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500302 u64_to_wwn(phba->cfg_soft_wwnn,
303 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400304 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500305 u64_to_wwn(phba->cfg_soft_wwpn,
306 vport->fc_sparam.portName.u.wwn);
307 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500308 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500309 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500310 sizeof (struct lpfc_name));
311 /* If no serial number in VPD data, use low 6 bytes of WWNN */
312 /* This should be consolidated into parse_vpd ? - mr */
313 if (phba->SerialNumber[0] == 0) {
314 uint8_t *outptr;
315
James Smart2e0fef82007-06-17 19:56:36 -0500316 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500317 for (i = 0; i < 12; i++) {
318 status = *outptr++;
319 j = ((status & 0xf0) >> 4);
320 if (j <= 9)
321 phba->SerialNumber[i] =
322 (char)((uint8_t) 0x30 + (uint8_t) j);
323 else
324 phba->SerialNumber[i] =
325 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
326 i++;
327 j = (status & 0xf);
328 if (j <= 9)
329 phba->SerialNumber[i] =
330 (char)((uint8_t) 0x30 + (uint8_t) j);
331 else
332 phba->SerialNumber[i] =
333 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
334 }
335 }
336
dea31012005-04-17 16:05:31 -0500337 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500338 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500339 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400341 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500342 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500343 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500344 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500345 mempool_free( pmb, phba->mbox_mem_pool);
346 return -EIO;
347 }
348
349 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
350 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
351 phba->cfg_hba_queue_depth =
352 mb->un.varRdConfig.max_xri + 1;
353
354 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500355
356 /* Get the default values for Model Name and Description */
357 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
358
359 if ((phba->cfg_link_speed > LINK_SPEED_10G)
360 || ((phba->cfg_link_speed == LINK_SPEED_1G)
361 && !(phba->lmt & LMT_1Gb))
362 || ((phba->cfg_link_speed == LINK_SPEED_2G)
363 && !(phba->lmt & LMT_2Gb))
364 || ((phba->cfg_link_speed == LINK_SPEED_4G)
365 && !(phba->lmt & LMT_4Gb))
366 || ((phba->cfg_link_speed == LINK_SPEED_8G)
367 && !(phba->lmt & LMT_8Gb))
368 || ((phba->cfg_link_speed == LINK_SPEED_10G)
369 && !(phba->lmt & LMT_10Gb))) {
370 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500371 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400372 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500373 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500374 phba->cfg_link_speed);
375 phba->cfg_link_speed = LINK_SPEED_AUTO;
376 }
377
James Smart2e0fef82007-06-17 19:56:36 -0500378 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500379
James Smart0b727fe2007-10-27 13:37:25 -0400380 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500381 if (psli->ring[psli->extra_ring].cmdringaddr)
382 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500383 if (psli->ring[psli->fcp_ring].cmdringaddr)
384 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
385 if (psli->ring[psli->next_ring].cmdringaddr)
386 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
387
388 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500389 if (phba->sli_rev != 3)
390 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500391
392 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500393 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500394 status = readl(phba->HCregaddr);
395 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
396 if (psli->num_rings > 0)
397 status |= HC_R0INT_ENA;
398 if (psli->num_rings > 1)
399 status |= HC_R1INT_ENA;
400 if (psli->num_rings > 2)
401 status |= HC_R2INT_ENA;
402 if (psli->num_rings > 3)
403 status |= HC_R3INT_ENA;
404
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500405 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
406 (phba->cfg_poll & DISABLE_FCP_RING_INT))
407 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
408
dea31012005-04-17 16:05:31 -0500409 writel(status, phba->HCregaddr);
410 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500411 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500412
413 /*
414 * Setup the ring 0 (els) timeout handler
415 */
416 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500417 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500418 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
419 phba->hb_outstanding = 0;
420 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500421
422 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
423 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400424 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400425 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400426 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400428 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500429 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500430 mb->mbxCommand, mb->mbxStatus);
431
432 /* Clear all interrupt enable conditions */
433 writel(0, phba->HCregaddr);
434 readl(phba->HCregaddr); /* flush */
435 /* Clear all pending interrupts */
436 writel(0xffffffff, phba->HAregaddr);
437 readl(phba->HAregaddr); /* flush */
438
James Smart2e0fef82007-06-17 19:56:36 -0500439 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400440 if (rc != MBX_BUSY)
441 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500442 return -EIO;
443 }
444 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400445 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
446 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
447 pmb->mbox_cmpl = lpfc_config_async_cmpl;
448 pmb->vport = phba->pport;
449 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500450
James Smart57127f12007-10-27 13:37:05 -0400451 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
452 lpfc_printf_log(phba,
453 KERN_ERR,
454 LOG_INIT,
455 "0456 Adapter failed to issue "
456 "ASYNCEVT_ENABLE mbox status x%x \n.",
457 rc);
458 mempool_free(pmb, phba->mbox_mem_pool);
459 }
James Smartd7c255b2008-08-24 21:50:00 -0400460 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400461}
462
James Smarte59058c2008-08-24 21:49:00 -0400463/**
464 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
465 * @phba: pointer to lpfc HBA data structure.
466 *
467 * This routine will do LPFC uninitialization before the HBA is reset when
468 * bringing down the SLI Layer.
469 *
470 * Return codes
471 * 0 - success.
472 * Any other value - error.
473 **/
dea31012005-04-17 16:05:31 -0500474int
James Smart2e0fef82007-06-17 19:56:36 -0500475lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500476{
James Smart1b32f6a2008-02-08 18:49:39 -0500477 struct lpfc_vport **vports;
478 int i;
dea31012005-04-17 16:05:31 -0500479 /* Disable interrupts */
480 writel(0, phba->HCregaddr);
481 readl(phba->HCregaddr); /* flush */
482
James Smart1b32f6a2008-02-08 18:49:39 -0500483 if (phba->pport->load_flag & FC_UNLOADING)
484 lpfc_cleanup_discovery_resources(phba->pport);
485 else {
486 vports = lpfc_create_vport_work_array(phba);
487 if (vports != NULL)
488 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
489 lpfc_cleanup_discovery_resources(vports[i]);
490 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500491 }
492 return 0;
dea31012005-04-17 16:05:31 -0500493}
494
James Smarte59058c2008-08-24 21:49:00 -0400495/**
496 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
497 * @phba: pointer to lpfc HBA data structure.
498 *
499 * This routine will do uninitialization after the HBA is reset when bring
500 * down the SLI Layer.
501 *
502 * Return codes
503 * 0 - sucess.
504 * Any other value - error.
505 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -0500506int
James Smart2e0fef82007-06-17 19:56:36 -0500507lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500508{
509 struct lpfc_sli *psli = &phba->sli;
510 struct lpfc_sli_ring *pring;
511 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500512 struct lpfc_iocbq *iocb;
513 IOCB_t *cmd = NULL;
514 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500515 int i;
516
James Smart92d7f7b2007-06-17 19:56:38 -0500517 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
518 lpfc_sli_hbqbuf_free_all(phba);
519 else {
520 /* Cleanup preposted buffers on the ELS ring */
521 pring = &psli->ring[LPFC_ELS_RING];
522 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
523 list_del(&mp->list);
524 pring->postbufq_cnt--;
525 lpfc_mbuf_free(phba, mp->virt, mp->phys);
526 kfree(mp);
527 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500528 }
529
James Smart09372822008-01-11 01:52:54 -0500530 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500531 for (i = 0; i < psli->num_rings; i++) {
532 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500533
534 /* At this point in time the HBA is either reset or DOA. Either
535 * way, nothing should be on txcmplq as it will NEVER complete.
536 */
537 list_splice_init(&pring->txcmplq, &completions);
538 pring->txcmplq_cnt = 0;
539 spin_unlock_irq(&phba->hbalock);
540
541 while (!list_empty(&completions)) {
542 iocb = list_get_first(&completions, struct lpfc_iocbq,
543 list);
544 cmd = &iocb->iocb;
545 list_del_init(&iocb->list);
546
547 if (!iocb->iocb_cmpl)
548 lpfc_sli_release_iocbq(phba, iocb);
549 else {
550 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
551 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
552 (iocb->iocb_cmpl) (phba, iocb, iocb);
553 }
554 }
555
Jamie Wellnitz41415862006-02-28 19:25:27 -0500556 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500557 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500558 }
James Smart09372822008-01-11 01:52:54 -0500559 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500560
561 return 0;
562}
563
James Smarte59058c2008-08-24 21:49:00 -0400564/**
565 * lpfc_hb_timeout: The HBA-timer timeout handler.
566 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
567 *
568 * This is the HBA-timer timeout handler registered to the lpfc driver. When
569 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
570 * work-port-events bitmap and the worker thread is notified. This timeout
571 * event will be used by the worker thread to invoke the actual timeout
572 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
573 * be performed in the timeout handler and the HBA timeout event bit shall
574 * be cleared by the worker thread after it has taken the event bitmap out.
575 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100576static void
James Smart858c9f62007-06-17 19:56:39 -0500577lpfc_hb_timeout(unsigned long ptr)
578{
579 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400580 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500581 unsigned long iflag;
582
583 phba = (struct lpfc_hba *)ptr;
584 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400585 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
586 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500587 phba->pport->work_port_events |= WORKER_HB_TMO;
588 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
589
James Smart5e9d9b82008-06-14 22:52:53 -0400590 if (!tmo_posted)
591 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500592 return;
593}
594
James Smarte59058c2008-08-24 21:49:00 -0400595/**
596 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
597 * @phba: pointer to lpfc hba data structure.
598 * @pmboxq: pointer to the driver internal queue element for mailbox command.
599 *
600 * This is the callback function to the lpfc heart-beat mailbox command.
601 * If configured, the lpfc driver issues the heart-beat mailbox command to
602 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
603 * heart-beat mailbox command is issued, the driver shall set up heart-beat
604 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
605 * heart-beat outstanding state. Once the mailbox command comes back and
606 * no error conditions detected, the heart-beat mailbox command timer is
607 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
608 * state is cleared for the next heart-beat. If the timer expired with the
609 * heart-beat outstanding state set, the driver will put the HBA offline.
610 **/
James Smart858c9f62007-06-17 19:56:39 -0500611static void
612lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
613{
614 unsigned long drvr_flag;
615
616 spin_lock_irqsave(&phba->hbalock, drvr_flag);
617 phba->hb_outstanding = 0;
618 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
619
620 mempool_free(pmboxq, phba->mbox_mem_pool);
621 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
622 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400623 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500624 mod_timer(&phba->hb_tmofunc,
625 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
626 return;
627}
628
James Smarte59058c2008-08-24 21:49:00 -0400629/**
630 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
631 * @phba: pointer to lpfc hba data structure.
632 *
633 * This is the actual HBA-timer timeout handler to be invoked by the worker
634 * thread whenever the HBA timer fired and HBA-timeout event posted. This
635 * handler performs any periodic operations needed for the device. If such
636 * periodic event has already been attended to either in the interrupt handler
637 * or by processing slow-ring or fast-ring events within the HBA-timer
638 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
639 * the timer for the next timeout period. If lpfc heart-beat mailbox command
640 * is configured and there is no heart-beat mailbox command outstanding, a
641 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
642 * has been a heart-beat mailbox command outstanding, the HBA shall be put
643 * to offline.
644 **/
James Smart858c9f62007-06-17 19:56:39 -0500645void
646lpfc_hb_timeout_handler(struct lpfc_hba *phba)
647{
648 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500649 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500650 int retval;
651 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500652 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500653
654 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400655 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500656 (phba->pport->fc_flag & FC_OFFLINE_MODE))
657 return;
658
659 spin_lock_irq(&phba->pport->work_port_lock);
660 /* If the timer is already canceled do nothing */
661 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
662 spin_unlock_irq(&phba->pport->work_port_lock);
663 return;
664 }
665
666 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
667 jiffies)) {
668 spin_unlock_irq(&phba->pport->work_port_lock);
669 if (!phba->hb_outstanding)
670 mod_timer(&phba->hb_tmofunc,
671 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
672 else
673 mod_timer(&phba->hb_tmofunc,
674 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
675 return;
676 }
677 spin_unlock_irq(&phba->pport->work_port_lock);
678
James Smart0ff10d42008-01-11 01:52:36 -0500679 if (phba->elsbuf_cnt &&
680 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
681 spin_lock_irq(&phba->hbalock);
682 list_splice_init(&phba->elsbuf, &completions);
683 phba->elsbuf_cnt = 0;
684 phba->elsbuf_prev_cnt = 0;
685 spin_unlock_irq(&phba->hbalock);
686
687 while (!list_empty(&completions)) {
688 list_remove_head(&completions, buf_ptr,
689 struct lpfc_dmabuf, list);
690 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
691 kfree(buf_ptr);
692 }
693 }
694 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
695
James Smart858c9f62007-06-17 19:56:39 -0500696 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500697 if (phba->cfg_enable_hba_heartbeat) {
698 if (!phba->hb_outstanding) {
699 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
700 if (!pmboxq) {
701 mod_timer(&phba->hb_tmofunc,
702 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
703 return;
704 }
705
706 lpfc_heart_beat(phba, pmboxq);
707 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
708 pmboxq->vport = phba->pport;
709 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
710
711 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
712 mempool_free(pmboxq, phba->mbox_mem_pool);
713 mod_timer(&phba->hb_tmofunc,
714 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
715 return;
716 }
James Smart858c9f62007-06-17 19:56:39 -0500717 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500718 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
719 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500720 return;
James Smart13815c82008-01-11 01:52:48 -0500721 } else {
722 /*
723 * If heart beat timeout called with hb_outstanding set
724 * we need to take the HBA offline.
725 */
726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
727 "0459 Adapter heartbeat failure, "
728 "taking this port offline.\n");
729
730 spin_lock_irq(&phba->hbalock);
731 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
732 spin_unlock_irq(&phba->hbalock);
733
734 lpfc_offline_prep(phba);
735 lpfc_offline(phba);
736 lpfc_unblock_mgmt_io(phba);
737 phba->link_state = LPFC_HBA_ERROR;
738 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500739 }
James Smart858c9f62007-06-17 19:56:39 -0500740 }
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
744 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
745 * @phba: pointer to lpfc hba data structure.
746 *
747 * This routine is called to bring the HBA offline when HBA hardware error
748 * other than Port Error 6 has been detected.
749 **/
James Smart09372822008-01-11 01:52:54 -0500750static void
751lpfc_offline_eratt(struct lpfc_hba *phba)
752{
753 struct lpfc_sli *psli = &phba->sli;
754
755 spin_lock_irq(&phba->hbalock);
756 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
757 spin_unlock_irq(&phba->hbalock);
758 lpfc_offline_prep(phba);
759
760 lpfc_offline(phba);
761 lpfc_reset_barrier(phba);
762 lpfc_sli_brdreset(phba);
763 lpfc_hba_down_post(phba);
764 lpfc_sli_brdready(phba, HS_MBRDY);
765 lpfc_unblock_mgmt_io(phba);
766 phba->link_state = LPFC_HBA_ERROR;
767 return;
768}
769
James Smarte59058c2008-08-24 21:49:00 -0400770/**
771 * lpfc_handle_eratt: The HBA hardware error handler.
772 * @phba: pointer to lpfc hba data structure.
773 *
774 * This routine is invoked to handle the following HBA hardware error
775 * conditions:
776 * 1 - HBA error attention interrupt
777 * 2 - DMA ring index out of range
778 * 3 - Mailbox command came back as unknown
779 **/
dea31012005-04-17 16:05:31 -0500780void
James Smart2e0fef82007-06-17 19:56:36 -0500781lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500782{
James Smart2e0fef82007-06-17 19:56:36 -0500783 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500784 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500785 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400786 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400787 unsigned long temperature;
788 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500789 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -0500790
Linas Vepstas8d63f372007-02-14 14:28:36 -0600791 /* If the pci channel is offline, ignore possible errors,
792 * since we cannot communicate with the pci card anyway. */
793 if (pci_channel_offline(phba->pcidev))
794 return;
James Smart13815c82008-01-11 01:52:48 -0500795 /* If resets are disabled then leave the HBA alone and return */
796 if (!phba->cfg_enable_hba_reset)
797 return;
dea31012005-04-17 16:05:31 -0500798
James Smart97eab632008-04-07 10:16:05 -0400799 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500800 /* Re-establishing Link */
801 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400802 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500803 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400804 phba->work_hs,
dea31012005-04-17 16:05:31 -0500805 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400806
James Smart92d7f7b2007-06-17 19:56:38 -0500807 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500808 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500809 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500810
811 /*
812 * Firmware stops when it triggled erratt with HS_FFER6.
813 * That could cause the I/Os dropped by the firmware.
814 * Error iocb (I/O) on txcmplq and let the SCSI layer
815 * retry it after re-establishing link.
816 */
817 pring = &psli->ring[psli->fcp_ring];
818 lpfc_sli_abort_iocb_ring(phba, pring);
819
dea31012005-04-17 16:05:31 -0500820 /*
821 * There was a firmware error. Take the hba offline and then
822 * attempt to restart it.
823 */
James Smart46fa3112007-04-25 09:51:45 -0400824 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500825 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500826 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500827 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400828 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500829 return;
830 }
James Smart46fa3112007-04-25 09:51:45 -0400831 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400832 } else if (phba->work_hs & HS_CRIT_TEMP) {
833 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
834 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
835 temp_event_data.event_code = LPFC_CRIT_TEMP;
836 temp_event_data.data = (uint32_t)temperature;
837
838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -0400839 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -0400840 "(%ld), taking this port offline "
841 "Data: x%x x%x x%x\n",
842 temperature, phba->work_hs,
843 phba->work_status[0], phba->work_status[1]);
844
845 shost = lpfc_shost_from_vport(phba->pport);
846 fc_host_post_vendor_event(shost, fc_get_event_number(),
847 sizeof(temp_event_data),
848 (char *) &temp_event_data,
849 SCSI_NL_VID_TYPE_PCI
850 | PCI_VENDOR_ID_EMULEX);
851
James Smart7af67052007-10-27 13:38:11 -0400852 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400853 phba->over_temp_state = HBA_OVER_TEMP;
854 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500855 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400856
dea31012005-04-17 16:05:31 -0500857 } else {
858 /* The if clause above forces this code path when the status
859 * failure is a value other than FFER6. Do not call the offline
860 * twice. This is the adapter hardware error path.
861 */
862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400863 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500864 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400865 phba->work_hs,
dea31012005-04-17 16:05:31 -0500866 phba->work_status[0], phba->work_status[1]);
867
James Smartd2873e42006-08-18 17:46:43 -0400868 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500869 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500870 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400871 sizeof(event_data), (char *) &event_data,
872 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
873
James Smart09372822008-01-11 01:52:54 -0500874 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500875 }
876}
877
James Smarte59058c2008-08-24 21:49:00 -0400878/**
879 * lpfc_handle_latt: The HBA link event handler.
880 * @phba: pointer to lpfc hba data structure.
881 *
882 * This routine is invoked from the worker thread to handle a HBA host
883 * attention link event.
884 **/
dea31012005-04-17 16:05:31 -0500885void
James Smart2e0fef82007-06-17 19:56:36 -0500886lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500887{
James Smart2e0fef82007-06-17 19:56:36 -0500888 struct lpfc_vport *vport = phba->pport;
889 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500890 LPFC_MBOXQ_t *pmb;
891 volatile uint32_t control;
892 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500893 int rc = 0;
dea31012005-04-17 16:05:31 -0500894
895 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500896 if (!pmb) {
897 rc = 1;
dea31012005-04-17 16:05:31 -0500898 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500899 }
dea31012005-04-17 16:05:31 -0500900
901 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500902 if (!mp) {
903 rc = 2;
dea31012005-04-17 16:05:31 -0500904 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500905 }
dea31012005-04-17 16:05:31 -0500906
907 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500908 if (!mp->virt) {
909 rc = 3;
dea31012005-04-17 16:05:31 -0500910 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500911 }
dea31012005-04-17 16:05:31 -0500912
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500913 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400914 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500915
916 psli->slistat.link_event++;
917 lpfc_read_la(phba, pmb, mp);
918 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500919 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -0400920 /* Block ELS IOCBs until we have processed this mbox command */
921 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -0400922 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500923 if (rc == MBX_NOT_FINISHED) {
924 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500925 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500926 }
dea31012005-04-17 16:05:31 -0500927
928 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500929 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500930 writel(HA_LATT, phba->HAregaddr);
931 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500932 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500933
934 return;
935
James Smart14691152006-12-02 13:34:28 -0500936lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -0400937 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -0500938 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500939lpfc_handle_latt_free_mp:
940 kfree(mp);
941lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400942 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500943lpfc_handle_latt_err_exit:
944 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500945 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500946 psli->sli_flag |= LPFC_PROCESS_LA;
947 control = readl(phba->HCregaddr);
948 control |= HC_LAINT_ENA;
949 writel(control, phba->HCregaddr);
950 readl(phba->HCregaddr); /* flush */
951
952 /* Clear Link Attention in HA REG */
953 writel(HA_LATT, phba->HAregaddr);
954 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500955 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500956 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500957 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500958
James Smart09372822008-01-11 01:52:54 -0500959 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
960 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500961
962 return;
963}
964
James Smarte59058c2008-08-24 21:49:00 -0400965/**
966 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
967 * @phba: pointer to lpfc hba data structure.
968 * @vpd: pointer to the vital product data.
969 * @len: length of the vital product data in bytes.
970 *
971 * This routine parses the Vital Product Data (VPD). The VPD is treated as
972 * an array of characters. In this routine, the ModelName, ProgramType, and
973 * ModelDesc, etc. fields of the phba data structure will be populated.
974 *
975 * Return codes
976 * 0 - pointer to the VPD passed in is NULL
977 * 1 - success
978 **/
dea31012005-04-17 16:05:31 -0500979static int
James Smart2e0fef82007-06-17 19:56:36 -0500980lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500981{
982 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500983 int Length;
dea31012005-04-17 16:05:31 -0500984 int i, j;
985 int finished = 0;
986 int index = 0;
987
988 if (!vpd)
989 return 0;
990
991 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400993 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500994 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
995 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500996 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500997 switch (vpd[index]) {
998 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500999 case 0x91:
dea31012005-04-17 16:05:31 -05001000 index += 1;
1001 lenlo = vpd[index];
1002 index += 1;
1003 lenhi = vpd[index];
1004 index += 1;
1005 i = ((((unsigned short)lenhi) << 8) + lenlo);
1006 index += i;
1007 break;
1008 case 0x90:
1009 index += 1;
1010 lenlo = vpd[index];
1011 index += 1;
1012 lenhi = vpd[index];
1013 index += 1;
1014 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001015 if (Length > len - index)
1016 Length = len - index;
dea31012005-04-17 16:05:31 -05001017 while (Length > 0) {
1018 /* Look for Serial Number */
1019 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1020 index += 2;
1021 i = vpd[index];
1022 index += 1;
1023 j = 0;
1024 Length -= (3+i);
1025 while(i--) {
1026 phba->SerialNumber[j++] = vpd[index++];
1027 if (j == 31)
1028 break;
1029 }
1030 phba->SerialNumber[j] = 0;
1031 continue;
1032 }
1033 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1034 phba->vpd_flag |= VPD_MODEL_DESC;
1035 index += 2;
1036 i = vpd[index];
1037 index += 1;
1038 j = 0;
1039 Length -= (3+i);
1040 while(i--) {
1041 phba->ModelDesc[j++] = vpd[index++];
1042 if (j == 255)
1043 break;
1044 }
1045 phba->ModelDesc[j] = 0;
1046 continue;
1047 }
1048 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1049 phba->vpd_flag |= VPD_MODEL_NAME;
1050 index += 2;
1051 i = vpd[index];
1052 index += 1;
1053 j = 0;
1054 Length -= (3+i);
1055 while(i--) {
1056 phba->ModelName[j++] = vpd[index++];
1057 if (j == 79)
1058 break;
1059 }
1060 phba->ModelName[j] = 0;
1061 continue;
1062 }
1063 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1064 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1065 index += 2;
1066 i = vpd[index];
1067 index += 1;
1068 j = 0;
1069 Length -= (3+i);
1070 while(i--) {
1071 phba->ProgramType[j++] = vpd[index++];
1072 if (j == 255)
1073 break;
1074 }
1075 phba->ProgramType[j] = 0;
1076 continue;
1077 }
1078 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1079 phba->vpd_flag |= VPD_PORT;
1080 index += 2;
1081 i = vpd[index];
1082 index += 1;
1083 j = 0;
1084 Length -= (3+i);
1085 while(i--) {
1086 phba->Port[j++] = vpd[index++];
1087 if (j == 19)
1088 break;
1089 }
1090 phba->Port[j] = 0;
1091 continue;
1092 }
1093 else {
1094 index += 2;
1095 i = vpd[index];
1096 index += 1;
1097 index += i;
1098 Length -= (3 + i);
1099 }
1100 }
1101 finished = 0;
1102 break;
1103 case 0x78:
1104 finished = 1;
1105 break;
1106 default:
1107 index ++;
1108 break;
1109 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001110 }
dea31012005-04-17 16:05:31 -05001111
1112 return(1);
1113}
1114
James Smarte59058c2008-08-24 21:49:00 -04001115/**
1116 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1117 * @phba: pointer to lpfc hba data structure.
1118 * @mdp: pointer to the data structure to hold the derived model name.
1119 * @descp: pointer to the data structure to hold the derived description.
1120 *
1121 * This routine retrieves HBA's description based on its registered PCI device
1122 * ID. The @descp passed into this function points to an array of 256 chars. It
1123 * shall be returned with the model name, maximum speed, and the host bus type.
1124 * The @mdp passed into this function points to an array of 80 chars. When the
1125 * function returns, the @mdp will be filled with the model name.
1126 **/
dea31012005-04-17 16:05:31 -05001127static void
James Smart2e0fef82007-06-17 19:56:36 -05001128lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001129{
1130 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001131 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001132 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001133 int GE = 0;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001134 struct {
1135 char * name;
1136 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001137 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001138 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001139
1140 if (mdp && mdp[0] != '\0'
1141 && descp && descp[0] != '\0')
1142 return;
1143
1144 if (phba->lmt & LMT_10Gb)
1145 max_speed = 10;
1146 else if (phba->lmt & LMT_8Gb)
1147 max_speed = 8;
1148 else if (phba->lmt & LMT_4Gb)
1149 max_speed = 4;
1150 else if (phba->lmt & LMT_2Gb)
1151 max_speed = 2;
1152 else
1153 max_speed = 1;
dea31012005-04-17 16:05:31 -05001154
1155 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001156
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001157 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001158 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001159 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001160 break;
dea31012005-04-17 16:05:31 -05001161 case PCI_DEVICE_ID_SUPERFLY:
1162 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001163 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001164 else
James Smart18a3b592006-12-02 13:35:08 -05001165 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001166 break;
1167 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001168 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001169 break;
1170 case PCI_DEVICE_ID_CENTAUR:
1171 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001172 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001173 else
James Smart18a3b592006-12-02 13:35:08 -05001174 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001175 break;
1176 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001177 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001178 break;
1179 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001180 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001181 break;
1182 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001183 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001184 break;
1185 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001186 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001187 break;
1188 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001189 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001190 break;
1191 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001192 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001193 break;
1194 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001195 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001196 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001197 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001198 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001199 break;
1200 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001201 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001202 break;
1203 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001204 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001205 break;
1206 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001207 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001208 break;
1209 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001210 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001211 break;
dea31012005-04-17 16:05:31 -05001212 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001213 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001214 break;
1215 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001216 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001217 break;
1218 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001219 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001220 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001221 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001222 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001223 break;
1224 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001225 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001226 break;
dea31012005-04-17 16:05:31 -05001227 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001228 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001229 break;
1230 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001231 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001232 break;
1233 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001234 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001235 break;
1236 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001237 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001238 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001239 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001240 m = (typeof(m)){"LP11000-S", max_speed,
1241 "PCI-X2"};
1242 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001243 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001244 m = (typeof(m)){"LPe11000-S", max_speed,
1245 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001246 break;
James Smartb87eab32007-04-25 09:53:28 -04001247 case PCI_DEVICE_ID_SAT:
1248 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1249 break;
1250 case PCI_DEVICE_ID_SAT_MID:
1251 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1252 break;
1253 case PCI_DEVICE_ID_SAT_SMB:
1254 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1255 break;
1256 case PCI_DEVICE_ID_SAT_DCSP:
1257 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1258 break;
1259 case PCI_DEVICE_ID_SAT_SCSP:
1260 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1261 break;
1262 case PCI_DEVICE_ID_SAT_S:
1263 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1264 break;
James Smart84774a42008-08-24 21:50:06 -04001265 case PCI_DEVICE_ID_HORNET:
1266 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1267 GE = 1;
1268 break;
1269 case PCI_DEVICE_ID_PROTEUS_VF:
1270 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1271 break;
1272 case PCI_DEVICE_ID_PROTEUS_PF:
1273 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1274 break;
1275 case PCI_DEVICE_ID_PROTEUS_S:
1276 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1277 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001278 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001279 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001280 break;
dea31012005-04-17 16:05:31 -05001281 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001282
1283 if (mdp && mdp[0] == '\0')
1284 snprintf(mdp, 79,"%s", m.name);
1285 if (descp && descp[0] == '\0')
1286 snprintf(descp, 255,
James Smart84774a42008-08-24 21:50:06 -04001287 "Emulex %s %d%s %s %s",
1288 m.name, m.max_speed,
1289 (GE) ? "GE" : "Gb",
1290 m.bus,
1291 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
dea31012005-04-17 16:05:31 -05001292}
1293
James Smarte59058c2008-08-24 21:49:00 -04001294/**
1295 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1296 * @phba: pointer to lpfc hba data structure.
1297 * @pring: pointer to a IOCB ring.
1298 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1299 *
1300 * This routine posts a given number of IOCBs with the associated DMA buffer
1301 * descriptors specified by the cnt argument to the given IOCB ring.
1302 *
1303 * Return codes
1304 * The number of IOCBs NOT able to be posted to the IOCB ring.
1305 **/
dea31012005-04-17 16:05:31 -05001306int
James Smart495a7142008-06-14 22:52:59 -04001307lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001308{
1309 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001310 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001311 struct lpfc_dmabuf *mp1, *mp2;
1312
1313 cnt += pring->missbufcnt;
1314
1315 /* While there are buffers to post */
1316 while (cnt > 0) {
1317 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001318 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001319 if (iocb == NULL) {
1320 pring->missbufcnt = cnt;
1321 return cnt;
1322 }
dea31012005-04-17 16:05:31 -05001323 icmd = &iocb->iocb;
1324
1325 /* 2 buffers can be posted per command */
1326 /* Allocate buffer to post */
1327 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1328 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001329 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1330 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001331 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001332 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001333 pring->missbufcnt = cnt;
1334 return cnt;
1335 }
1336
1337 INIT_LIST_HEAD(&mp1->list);
1338 /* Allocate buffer to post */
1339 if (cnt > 1) {
1340 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1341 if (mp2)
1342 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1343 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001344 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001345 kfree(mp2);
dea31012005-04-17 16:05:31 -05001346 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1347 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001348 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001349 pring->missbufcnt = cnt;
1350 return cnt;
1351 }
1352
1353 INIT_LIST_HEAD(&mp2->list);
1354 } else {
1355 mp2 = NULL;
1356 }
1357
1358 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1359 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1360 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1361 icmd->ulpBdeCount = 1;
1362 cnt--;
1363 if (mp2) {
1364 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1365 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1366 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1367 cnt--;
1368 icmd->ulpBdeCount = 2;
1369 }
1370
1371 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1372 icmd->ulpLe = 1;
1373
dea31012005-04-17 16:05:31 -05001374 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1375 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1376 kfree(mp1);
1377 cnt++;
1378 if (mp2) {
1379 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1380 kfree(mp2);
1381 cnt++;
1382 }
James Bottomley604a3e32005-10-29 10:28:33 -05001383 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001384 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001385 return cnt;
1386 }
dea31012005-04-17 16:05:31 -05001387 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001388 if (mp2)
dea31012005-04-17 16:05:31 -05001389 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001390 }
1391 pring->missbufcnt = 0;
1392 return 0;
1393}
1394
James Smarte59058c2008-08-24 21:49:00 -04001395/**
1396 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1397 * @phba: pointer to lpfc hba data structure.
1398 *
1399 * This routine posts initial receive IOCB buffers to the ELS ring. The
1400 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1401 * set to 64 IOCBs.
1402 *
1403 * Return codes
1404 * 0 - success (currently always success)
1405 **/
dea31012005-04-17 16:05:31 -05001406static int
James Smart2e0fef82007-06-17 19:56:36 -05001407lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001408{
1409 struct lpfc_sli *psli = &phba->sli;
1410
1411 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001412 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001413 /* Ring 2 - FCP no buffers needed */
1414
1415 return 0;
1416}
1417
1418#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1419
James Smarte59058c2008-08-24 21:49:00 -04001420/**
1421 * lpfc_sha_init: Set up initial array of hash table entries.
1422 * @HashResultPointer: pointer to an array as hash table.
1423 *
1424 * This routine sets up the initial values to the array of hash table entries
1425 * for the LC HBAs.
1426 **/
dea31012005-04-17 16:05:31 -05001427static void
1428lpfc_sha_init(uint32_t * HashResultPointer)
1429{
1430 HashResultPointer[0] = 0x67452301;
1431 HashResultPointer[1] = 0xEFCDAB89;
1432 HashResultPointer[2] = 0x98BADCFE;
1433 HashResultPointer[3] = 0x10325476;
1434 HashResultPointer[4] = 0xC3D2E1F0;
1435}
1436
James Smarte59058c2008-08-24 21:49:00 -04001437/**
1438 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1439 * @HashResultPointer: pointer to an initial/result hash table.
1440 * @HashWorkingPointer: pointer to an working hash table.
1441 *
1442 * This routine iterates an initial hash table pointed by @HashResultPointer
1443 * with the values from the working hash table pointeed by @HashWorkingPointer.
1444 * The results are putting back to the initial hash table, returned through
1445 * the @HashResultPointer as the result hash table.
1446 **/
dea31012005-04-17 16:05:31 -05001447static void
1448lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1449{
1450 int t;
1451 uint32_t TEMP;
1452 uint32_t A, B, C, D, E;
1453 t = 16;
1454 do {
1455 HashWorkingPointer[t] =
1456 S(1,
1457 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1458 8] ^
1459 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1460 } while (++t <= 79);
1461 t = 0;
1462 A = HashResultPointer[0];
1463 B = HashResultPointer[1];
1464 C = HashResultPointer[2];
1465 D = HashResultPointer[3];
1466 E = HashResultPointer[4];
1467
1468 do {
1469 if (t < 20) {
1470 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1471 } else if (t < 40) {
1472 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1473 } else if (t < 60) {
1474 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1475 } else {
1476 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1477 }
1478 TEMP += S(5, A) + E + HashWorkingPointer[t];
1479 E = D;
1480 D = C;
1481 C = S(30, B);
1482 B = A;
1483 A = TEMP;
1484 } while (++t <= 79);
1485
1486 HashResultPointer[0] += A;
1487 HashResultPointer[1] += B;
1488 HashResultPointer[2] += C;
1489 HashResultPointer[3] += D;
1490 HashResultPointer[4] += E;
1491
1492}
1493
James Smarte59058c2008-08-24 21:49:00 -04001494/**
1495 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1496 * @RandomChallenge: pointer to the entry of host challenge random number array.
1497 * @HashWorking: pointer to the entry of the working hash array.
1498 *
1499 * This routine calculates the working hash array referred by @HashWorking
1500 * from the challenge random numbers associated with the host, referred by
1501 * @RandomChallenge. The result is put into the entry of the working hash
1502 * array and returned by reference through @HashWorking.
1503 **/
dea31012005-04-17 16:05:31 -05001504static void
1505lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1506{
1507 *HashWorking = (*RandomChallenge ^ *HashWorking);
1508}
1509
James Smarte59058c2008-08-24 21:49:00 -04001510/**
1511 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1512 * @phba: pointer to lpfc hba data structure.
1513 * @hbainit: pointer to an array of unsigned 32-bit integers.
1514 *
1515 * This routine performs the special handling for LC HBA initialization.
1516 **/
dea31012005-04-17 16:05:31 -05001517void
1518lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1519{
1520 int t;
1521 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001522 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001523
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001524 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001525 if (!HashWorking)
1526 return;
1527
dea31012005-04-17 16:05:31 -05001528 HashWorking[0] = HashWorking[78] = *pwwnn++;
1529 HashWorking[1] = HashWorking[79] = *pwwnn;
1530
1531 for (t = 0; t < 7; t++)
1532 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1533
1534 lpfc_sha_init(hbainit);
1535 lpfc_sha_iterate(hbainit, HashWorking);
1536 kfree(HashWorking);
1537}
1538
James Smarte59058c2008-08-24 21:49:00 -04001539/**
1540 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1541 * @vport: pointer to a virtual N_Port data structure.
1542 *
1543 * This routine performs the necessary cleanups before deleting the @vport.
1544 * It invokes the discovery state machine to perform necessary state
1545 * transitions and to release the ndlps associated with the @vport. Note,
1546 * the physical port is treated as @vport 0.
1547 **/
James Smart87af33f2007-10-27 13:37:43 -04001548void
James Smart2e0fef82007-06-17 19:56:36 -05001549lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001550{
James Smart87af33f2007-10-27 13:37:43 -04001551 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001552 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001553 int i = 0;
dea31012005-04-17 16:05:31 -05001554
James Smart87af33f2007-10-27 13:37:43 -04001555 if (phba->link_state > LPFC_LINK_DOWN)
1556 lpfc_port_link_failure(vport);
1557
1558 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001559 if (!NLP_CHK_NODE_ACT(ndlp)) {
1560 ndlp = lpfc_enable_node(vport, ndlp,
1561 NLP_STE_UNUSED_NODE);
1562 if (!ndlp)
1563 continue;
1564 spin_lock_irq(&phba->ndlp_lock);
1565 NLP_SET_FREE_REQ(ndlp);
1566 spin_unlock_irq(&phba->ndlp_lock);
1567 /* Trigger the release of the ndlp memory */
1568 lpfc_nlp_put(ndlp);
1569 continue;
1570 }
1571 spin_lock_irq(&phba->ndlp_lock);
1572 if (NLP_CHK_FREE_REQ(ndlp)) {
1573 /* The ndlp should not be in memory free mode already */
1574 spin_unlock_irq(&phba->ndlp_lock);
1575 continue;
1576 } else
1577 /* Indicate request for freeing ndlp memory */
1578 NLP_SET_FREE_REQ(ndlp);
1579 spin_unlock_irq(&phba->ndlp_lock);
1580
James Smart58da1ff2008-04-07 10:15:56 -04001581 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1582 ndlp->nlp_DID == Fabric_DID) {
1583 /* Just free up ndlp with Fabric_DID for vports */
1584 lpfc_nlp_put(ndlp);
1585 continue;
1586 }
1587
James Smart87af33f2007-10-27 13:37:43 -04001588 if (ndlp->nlp_type & NLP_FABRIC)
1589 lpfc_disc_state_machine(vport, ndlp, NULL,
1590 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001591
James Smart87af33f2007-10-27 13:37:43 -04001592 lpfc_disc_state_machine(vport, ndlp, NULL,
1593 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001594
James Smart87af33f2007-10-27 13:37:43 -04001595 }
1596
James Smarta8adb832007-10-27 13:37:53 -04001597 /* At this point, ALL ndlp's should be gone
1598 * because of the previous NLP_EVT_DEVICE_RM.
1599 * Lets wait for this to happen, if needed.
1600 */
James Smart87af33f2007-10-27 13:37:43 -04001601 while (!list_empty(&vport->fc_nodes)) {
1602
James Smarta8adb832007-10-27 13:37:53 -04001603 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001604 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001605 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001606 list_for_each_entry_safe(ndlp, next_ndlp,
1607 &vport->fc_nodes, nlp_listp) {
1608 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1609 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001610 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001611 "usgmap:x%x refcnt:%d\n",
1612 ndlp->nlp_DID, (void *)ndlp,
1613 ndlp->nlp_usg_map,
1614 atomic_read(
1615 &ndlp->kref.refcount));
1616 }
James Smarta8adb832007-10-27 13:37:53 -04001617 break;
James Smart87af33f2007-10-27 13:37:43 -04001618 }
James Smarta8adb832007-10-27 13:37:53 -04001619
1620 /* Wait for any activity on ndlps to settle */
1621 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001622 }
dea31012005-04-17 16:05:31 -05001623 return;
1624}
1625
James Smarte59058c2008-08-24 21:49:00 -04001626/**
1627 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1628 * @vport: pointer to a virtual N_Port data structure.
1629 *
1630 * This routine stops all the timers associated with a @vport. This function
1631 * is invoked before disabling or deleting a @vport. Note that the physical
1632 * port is treated as @vport 0.
1633 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001634void
1635lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001636{
James Smart92d7f7b2007-06-17 19:56:38 -05001637 del_timer_sync(&vport->els_tmofunc);
1638 del_timer_sync(&vport->fc_fdmitmo);
1639 lpfc_can_disctmo(vport);
1640 return;
dea31012005-04-17 16:05:31 -05001641}
1642
James Smarte59058c2008-08-24 21:49:00 -04001643/**
1644 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1645 * @phba: pointer to lpfc hba data structure.
1646 *
1647 * This routine stops all the timers associated with a HBA. This function is
1648 * invoked before either putting a HBA offline or unloading the driver.
1649 **/
James Smart2e0fef82007-06-17 19:56:36 -05001650static void
James Smart92d7f7b2007-06-17 19:56:38 -05001651lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001652{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001653 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001654 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001655 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001656 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001657 phba->hb_outstanding = 0;
1658 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001659 return;
dea31012005-04-17 16:05:31 -05001660}
1661
James Smarte59058c2008-08-24 21:49:00 -04001662/**
1663 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1664 * @phba: pointer to lpfc hba data structure.
1665 *
1666 * This routine marks a HBA's management interface as blocked. Once the HBA's
1667 * management interface is marked as blocked, all the user space access to
1668 * the HBA, whether they are from sysfs interface or libdfc interface will
1669 * all be blocked. The HBA is set to block the management interface when the
1670 * driver prepares the HBA interface for online or offline.
1671 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001672static void
1673lpfc_block_mgmt_io(struct lpfc_hba * phba)
1674{
1675 unsigned long iflag;
1676
1677 spin_lock_irqsave(&phba->hbalock, iflag);
1678 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1679 spin_unlock_irqrestore(&phba->hbalock, iflag);
1680}
1681
James Smarte59058c2008-08-24 21:49:00 -04001682/**
1683 * lpfc_online: Initialize and bring a HBA online.
1684 * @phba: pointer to lpfc hba data structure.
1685 *
1686 * This routine initializes the HBA and brings a HBA online. During this
1687 * process, the management interface is blocked to prevent user space access
1688 * to the HBA interfering with the driver initialization.
1689 *
1690 * Return codes
1691 * 0 - successful
1692 * 1 - failed
1693 **/
dea31012005-04-17 16:05:31 -05001694int
James Smart2e0fef82007-06-17 19:56:36 -05001695lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001696{
James Smart2e0fef82007-06-17 19:56:36 -05001697 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001698 struct lpfc_vport **vports;
1699 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001700
dea31012005-04-17 16:05:31 -05001701 if (!phba)
1702 return 0;
1703
James Smart2e0fef82007-06-17 19:56:36 -05001704 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001705 return 0;
1706
James Smarted957682007-06-17 19:56:37 -05001707 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001708 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001709
James Smart46fa3112007-04-25 09:51:45 -04001710 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001711
James Smart46fa3112007-04-25 09:51:45 -04001712 if (!lpfc_sli_queue_setup(phba)) {
1713 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001714 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001715 }
1716
1717 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1718 lpfc_unblock_mgmt_io(phba);
1719 return 1;
1720 }
dea31012005-04-17 16:05:31 -05001721
James Smart549e55c2007-08-02 11:09:51 -04001722 vports = lpfc_create_vport_work_array(phba);
1723 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001724 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001725 struct Scsi_Host *shost;
1726 shost = lpfc_shost_from_vport(vports[i]);
1727 spin_lock_irq(shost->host_lock);
1728 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1729 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1730 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1731 spin_unlock_irq(shost->host_lock);
1732 }
James Smart09372822008-01-11 01:52:54 -05001733 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001734
James Smart46fa3112007-04-25 09:51:45 -04001735 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001736 return 0;
1737}
1738
James Smarte59058c2008-08-24 21:49:00 -04001739/**
1740 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1741 * @phba: pointer to lpfc hba data structure.
1742 *
1743 * This routine marks a HBA's management interface as not blocked. Once the
1744 * HBA's management interface is marked as not blocked, all the user space
1745 * access to the HBA, whether they are from sysfs interface or libdfc
1746 * interface will be allowed. The HBA is set to block the management interface
1747 * when the driver prepares the HBA interface for online or offline and then
1748 * set to unblock the management interface afterwards.
1749 **/
James Smart46fa3112007-04-25 09:51:45 -04001750void
James Smart46fa3112007-04-25 09:51:45 -04001751lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1752{
1753 unsigned long iflag;
1754
James Smart2e0fef82007-06-17 19:56:36 -05001755 spin_lock_irqsave(&phba->hbalock, iflag);
1756 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1757 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001758}
1759
James Smarte59058c2008-08-24 21:49:00 -04001760/**
1761 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1762 * @phba: pointer to lpfc hba data structure.
1763 *
1764 * This routine is invoked to prepare a HBA to be brought offline. It performs
1765 * unregistration login to all the nodes on all vports and flushes the mailbox
1766 * queue to make it ready to be brought offline.
1767 **/
James Smart46fa3112007-04-25 09:51:45 -04001768void
1769lpfc_offline_prep(struct lpfc_hba * phba)
1770{
James Smart2e0fef82007-06-17 19:56:36 -05001771 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001772 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001773 struct lpfc_vport **vports;
1774 int i;
dea31012005-04-17 16:05:31 -05001775
James Smart2e0fef82007-06-17 19:56:36 -05001776 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001777 return;
dea31012005-04-17 16:05:31 -05001778
James Smart46fa3112007-04-25 09:51:45 -04001779 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001780
1781 lpfc_linkdown(phba);
1782
James Smart87af33f2007-10-27 13:37:43 -04001783 /* Issue an unreg_login to all nodes on all vports */
1784 vports = lpfc_create_vport_work_array(phba);
1785 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001786 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001787 struct Scsi_Host *shost;
1788
James Smarta8adb832007-10-27 13:37:53 -04001789 if (vports[i]->load_flag & FC_UNLOADING)
1790 continue;
James Smart87af33f2007-10-27 13:37:43 -04001791 shost = lpfc_shost_from_vport(vports[i]);
1792 list_for_each_entry_safe(ndlp, next_ndlp,
1793 &vports[i]->fc_nodes,
1794 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001795 if (!NLP_CHK_NODE_ACT(ndlp))
1796 continue;
James Smart87af33f2007-10-27 13:37:43 -04001797 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1798 continue;
1799 if (ndlp->nlp_type & NLP_FABRIC) {
1800 lpfc_disc_state_machine(vports[i], ndlp,
1801 NULL, NLP_EVT_DEVICE_RECOVERY);
1802 lpfc_disc_state_machine(vports[i], ndlp,
1803 NULL, NLP_EVT_DEVICE_RM);
1804 }
1805 spin_lock_irq(shost->host_lock);
1806 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1807 spin_unlock_irq(shost->host_lock);
1808 lpfc_unreg_rpi(vports[i], ndlp);
1809 }
1810 }
1811 }
James Smart09372822008-01-11 01:52:54 -05001812 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001813
James Smart46fa3112007-04-25 09:51:45 -04001814 lpfc_sli_flush_mbox_queue(phba);
1815}
1816
James Smarte59058c2008-08-24 21:49:00 -04001817/**
1818 * lpfc_offline: Bring a HBA offline.
1819 * @phba: pointer to lpfc hba data structure.
1820 *
1821 * This routine actually brings a HBA offline. It stops all the timers
1822 * associated with the HBA, brings down the SLI layer, and eventually
1823 * marks the HBA as in offline state for the upper layer protocol.
1824 **/
James Smart46fa3112007-04-25 09:51:45 -04001825void
James Smart2e0fef82007-06-17 19:56:36 -05001826lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001827{
James Smart549e55c2007-08-02 11:09:51 -04001828 struct Scsi_Host *shost;
1829 struct lpfc_vport **vports;
1830 int i;
James Smart46fa3112007-04-25 09:51:45 -04001831
James Smart549e55c2007-08-02 11:09:51 -04001832 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001833 return;
James Smart688a8862006-07-06 15:49:56 -04001834
dea31012005-04-17 16:05:31 -05001835 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001836 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001837 vports = lpfc_create_vport_work_array(phba);
1838 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001839 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001840 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001841 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001842 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001843 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001844 /* Bring down the SLI Layer and cleanup. The HBA is offline
1845 now. */
1846 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001847 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001848 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001849 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001850 vports = lpfc_create_vport_work_array(phba);
1851 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001852 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001853 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001854 spin_lock_irq(shost->host_lock);
1855 vports[i]->work_port_events = 0;
1856 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1857 spin_unlock_irq(shost->host_lock);
1858 }
James Smart09372822008-01-11 01:52:54 -05001859 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001860}
1861
James Smarte59058c2008-08-24 21:49:00 -04001862/**
1863 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1864 * @phba: pointer to lpfc hba data structure.
1865 *
1866 * This routine is to free all the SCSI buffers and IOCBs from the driver
1867 * list back to kernel. It is called from lpfc_pci_remove_one to free
1868 * the internal resources before the device is removed from the system.
1869 *
1870 * Return codes
1871 * 0 - successful (for now, it always returns 0)
1872 **/
dea31012005-04-17 16:05:31 -05001873static int
James Smart2e0fef82007-06-17 19:56:36 -05001874lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001875{
1876 struct lpfc_scsi_buf *sb, *sb_next;
1877 struct lpfc_iocbq *io, *io_next;
1878
James Smart2e0fef82007-06-17 19:56:36 -05001879 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001880 /* Release all the lpfc_scsi_bufs maintained by this host. */
1881 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1882 list_del(&sb->list);
1883 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001884 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001885 kfree(sb);
1886 phba->total_scsi_bufs--;
1887 }
1888
1889 /* Release all the lpfc_iocbq entries maintained by this host. */
1890 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1891 list_del(&io->list);
1892 kfree(io);
1893 phba->total_iocbq_bufs--;
1894 }
1895
James Smart2e0fef82007-06-17 19:56:36 -05001896 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001897
1898 return 0;
1899}
1900
James Smarte59058c2008-08-24 21:49:00 -04001901/**
1902 * lpfc_create_port: Create an FC port.
1903 * @phba: pointer to lpfc hba data structure.
1904 * @instance: a unique integer ID to this FC port.
1905 * @dev: pointer to the device data structure.
1906 *
1907 * This routine creates a FC port for the upper layer protocol. The FC port
1908 * can be created on top of either a physical port or a virtual port provided
1909 * by the HBA. This routine also allocates a SCSI host data structure (shost)
1910 * and associates the FC port created before adding the shost into the SCSI
1911 * layer.
1912 *
1913 * Return codes
1914 * @vport - pointer to the virtual N_Port data structure.
1915 * NULL - port create failed.
1916 **/
James Smart2e0fef82007-06-17 19:56:36 -05001917struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001918lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001919{
James Smart2e0fef82007-06-17 19:56:36 -05001920 struct lpfc_vport *vport;
1921 struct Scsi_Host *shost;
1922 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001923
James Smart3de2a652007-08-02 11:09:59 -04001924 if (dev != &phba->pcidev->dev)
1925 shost = scsi_host_alloc(&lpfc_vport_template,
1926 sizeof(struct lpfc_vport));
1927 else
1928 shost = scsi_host_alloc(&lpfc_template,
1929 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001930 if (!shost)
1931 goto out;
James Smart47a86172007-04-25 09:53:22 -04001932
James Smart2e0fef82007-06-17 19:56:36 -05001933 vport = (struct lpfc_vport *) shost->hostdata;
1934 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05001935 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001936 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05001937 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04001938
James Smart3de2a652007-08-02 11:09:59 -04001939 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001940 shost->unique_id = instance;
1941 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001942 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001943 shost->this_id = -1;
1944 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001945 /*
James Smart2e0fef82007-06-17 19:56:36 -05001946 * Set initial can_queue value since 0 is no longer supported and
1947 * scsi_add_host will fail. This will be adjusted later based on the
1948 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001949 */
James Smart2e0fef82007-06-17 19:56:36 -05001950 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001951 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001952 shost->transportt = lpfc_vport_transport_template;
1953 vport->port_type = LPFC_NPIV_PORT;
1954 } else {
1955 shost->transportt = lpfc_transport_template;
1956 vport->port_type = LPFC_PHYSICAL_PORT;
1957 }
James Smart47a86172007-04-25 09:53:22 -04001958
James Smart2e0fef82007-06-17 19:56:36 -05001959 /* Initialize all internally managed lists. */
1960 INIT_LIST_HEAD(&vport->fc_nodes);
1961 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001962
James Smart2e0fef82007-06-17 19:56:36 -05001963 init_timer(&vport->fc_disctmo);
1964 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001965 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001966
James Smart2e0fef82007-06-17 19:56:36 -05001967 init_timer(&vport->fc_fdmitmo);
1968 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001969 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001970
James Smart2e0fef82007-06-17 19:56:36 -05001971 init_timer(&vport->els_tmofunc);
1972 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001973 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001974
James Smart3de2a652007-08-02 11:09:59 -04001975 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001976 if (error)
1977 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001978
James Smart549e55c2007-08-02 11:09:51 -04001979 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001980 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001981 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001982 return vport;
James Smart47a86172007-04-25 09:53:22 -04001983
James Smart2e0fef82007-06-17 19:56:36 -05001984out_put_shost:
1985 scsi_host_put(shost);
1986out:
1987 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001988}
1989
James Smarte59058c2008-08-24 21:49:00 -04001990/**
1991 * destroy_port: Destroy an FC port.
1992 * @vport: pointer to an lpfc virtual N_Port data structure.
1993 *
1994 * This routine destroys a FC port from the upper layer protocol. All the
1995 * resources associated with the port are released.
1996 **/
James Smart2e0fef82007-06-17 19:56:36 -05001997void
1998destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001999{
James Smart92d7f7b2007-06-17 19:56:38 -05002000 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2001 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002002
James Smart92d7f7b2007-06-17 19:56:38 -05002003 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04002004
James Smart858c9f62007-06-17 19:56:39 -05002005 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002006 fc_remove_host(shost);
2007 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002008
James Smart92d7f7b2007-06-17 19:56:38 -05002009 spin_lock_irq(&phba->hbalock);
2010 list_del_init(&vport->listentry);
2011 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002012
James Smart92d7f7b2007-06-17 19:56:38 -05002013 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002014 return;
James Smart47a86172007-04-25 09:53:22 -04002015}
2016
James Smarte59058c2008-08-24 21:49:00 -04002017/**
2018 * lpfc_get_instance: Get a unique integer ID.
2019 *
2020 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2021 * uses the kernel idr facility to perform the task.
2022 *
2023 * Return codes:
2024 * instance - a unique integer ID allocated as the new instance.
2025 * -1 - lpfc get instance failed.
2026 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002027int
2028lpfc_get_instance(void)
2029{
2030 int instance = 0;
2031
2032 /* Assign an unused number */
2033 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2034 return -1;
2035 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2036 return -1;
2037 return instance;
2038}
2039
James Smarte59058c2008-08-24 21:49:00 -04002040/**
2041 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2042 * @shost: pointer to SCSI host data structure.
2043 * @time: elapsed time of the scan in jiffies.
2044 *
2045 * This routine is called by the SCSI layer with a SCSI host to determine
2046 * whether the scan host is finished.
2047 *
2048 * Note: there is no scan_start function as adapter initialization will have
2049 * asynchronously kicked off the link initialization.
2050 *
2051 * Return codes
2052 * 0 - SCSI host scan is not over yet.
2053 * 1 - SCSI host scan is over.
2054 **/
James Smart47a86172007-04-25 09:53:22 -04002055int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2056{
James Smart2e0fef82007-06-17 19:56:36 -05002057 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2058 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002059 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002060
James Smart858c9f62007-06-17 19:56:39 -05002061 spin_lock_irq(shost->host_lock);
2062
James Smart51ef4c22007-08-02 11:10:31 -04002063 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002064 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002065 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002066 }
James Smart2e0fef82007-06-17 19:56:36 -05002067 if (time >= 30 * HZ) {
2068 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002069 "0461 Scanning longer than 30 "
2070 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002071 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002072 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002073 }
2074 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2075 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002076 "0465 Link down longer than 15 "
2077 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002078 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002079 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002080 }
2081
James Smart2e0fef82007-06-17 19:56:36 -05002082 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002083 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002084 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002085 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002086 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002087 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002088 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002089 goto finished;
2090
2091 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002092
2093finished:
James Smart858c9f62007-06-17 19:56:39 -05002094 spin_unlock_irq(shost->host_lock);
2095 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002096}
2097
James Smarte59058c2008-08-24 21:49:00 -04002098/**
2099 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2100 * @shost: pointer to SCSI host data structure.
2101 *
2102 * This routine initializes a given SCSI host attributes on a FC port. The
2103 * SCSI host can be either on top of a physical port or a virtual port.
2104 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002105void lpfc_host_attrib_init(struct Scsi_Host *shost)
2106{
2107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2108 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002109 /*
James Smart2e0fef82007-06-17 19:56:36 -05002110 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002111 */
2112
James Smart2e0fef82007-06-17 19:56:36 -05002113 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2114 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002115 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2116
2117 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002118 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002119 fc_host_supported_fc4s(shost)[2] = 1;
2120 fc_host_supported_fc4s(shost)[7] = 1;
2121
James Smart92d7f7b2007-06-17 19:56:38 -05002122 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2123 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002124
2125 fc_host_supported_speeds(shost) = 0;
2126 if (phba->lmt & LMT_10Gb)
2127 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002128 if (phba->lmt & LMT_8Gb)
2129 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002130 if (phba->lmt & LMT_4Gb)
2131 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2132 if (phba->lmt & LMT_2Gb)
2133 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2134 if (phba->lmt & LMT_1Gb)
2135 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2136
2137 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002138 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2139 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002140
2141 /* This value is also unchanging */
2142 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002143 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002144 fc_host_active_fc4s(shost)[2] = 1;
2145 fc_host_active_fc4s(shost)[7] = 1;
2146
James Smart92d7f7b2007-06-17 19:56:38 -05002147 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002148 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002149 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002150 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002151}
dea31012005-04-17 16:05:31 -05002152
James Smarte59058c2008-08-24 21:49:00 -04002153/**
2154 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2155 * @phba: pointer to lpfc hba data structure.
2156 *
2157 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2158 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2159 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2160 * on the current availability of PCI vector resources. The device driver is
2161 * responsible for calling the individual request_irq() to register each MSI-X
2162 * vector with a interrupt handler, which is done in this function. Note that
2163 * later when device is unloading, the driver should always call free_irq()
2164 * on all MSI-X vectors it has done request_irq() on before calling
2165 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2166 * will be left with MSI-X enabled and leaks its vectors.
2167 *
2168 * Return codes
2169 * 0 - sucessful
2170 * other values - error
2171 **/
James Smartdb2378e2008-02-08 18:49:51 -05002172static int
2173lpfc_enable_msix(struct lpfc_hba *phba)
2174{
2175 int error;
2176
2177 phba->msix_entries[0].entry = 0;
2178 phba->msix_entries[0].vector = 0;
2179
2180 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
2181 ARRAY_SIZE(phba->msix_entries));
2182 if (error) {
2183 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2184 "0420 Enable MSI-X failed (%d), continuing "
2185 "with MSI\n", error);
2186 pci_disable_msix(phba->pcidev);
2187 return error;
2188 }
2189
2190 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
2191 LPFC_DRIVER_NAME, phba);
2192 if (error) {
2193 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2194 "0421 MSI-X request_irq failed (%d), "
2195 "continuing with MSI\n", error);
2196 pci_disable_msix(phba->pcidev);
2197 }
2198 return error;
2199}
2200
James Smarte59058c2008-08-24 21:49:00 -04002201/**
2202 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2203 * @phba: pointer to lpfc hba data structure.
2204 *
2205 * This routine is invoked to release the MSI-X vectors and then disable the
2206 * MSI-X interrupt mode.
2207 **/
James Smartdb2378e2008-02-08 18:49:51 -05002208static void
2209lpfc_disable_msix(struct lpfc_hba *phba)
2210{
2211 free_irq(phba->msix_entries[0].vector, phba);
2212 pci_disable_msix(phba->pcidev);
2213}
2214
James Smarte59058c2008-08-24 21:49:00 -04002215/**
2216 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2217 * @pdev: pointer to PCI device
2218 * @pid: pointer to PCI device identifier
2219 *
2220 * This routine is to be registered to the kernel's PCI subsystem. When an
2221 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2222 * PCI device-specific information of the device and driver to see if the
2223 * driver state that it can support this kind of device. If the match is
2224 * successful, the driver core invokes this routine. If this routine
2225 * determines it can claim the HBA, it does all the initialization that it
2226 * needs to do to handle the HBA properly.
2227 *
2228 * Return code
2229 * 0 - driver can claim the device
2230 * negative value - driver can not claim the device
2231 **/
dea31012005-04-17 16:05:31 -05002232static int __devinit
2233lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2234{
James Smart2e0fef82007-06-17 19:56:36 -05002235 struct lpfc_vport *vport = NULL;
2236 struct lpfc_hba *phba;
2237 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002238 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002239 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04002240 void *ptr;
dea31012005-04-17 16:05:31 -05002241 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04002242 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04002243 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05002244 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002245 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05002246
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01002247 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05002248 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002249 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05002250 goto out_disable_device;
2251
James Smart2e0fef82007-06-17 19:56:36 -05002252 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2253 if (!phba)
dea31012005-04-17 16:05:31 -05002254 goto out_release_regions;
2255
James Smart2e0fef82007-06-17 19:56:36 -05002256 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002257
James Smarte47c9092008-02-08 18:49:26 -05002258 /* Initialize ndlp management spinlock */
2259 spin_lock_init(&phba->ndlp_lock);
2260
dea31012005-04-17 16:05:31 -05002261 phba->pcidev = pdev;
2262
2263 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05002264 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05002265 goto out_free_phba;
dea31012005-04-17 16:05:31 -05002266
James Smart2e0fef82007-06-17 19:56:36 -05002267 INIT_LIST_HEAD(&phba->port_list);
James Smart84774a42008-08-24 21:50:06 -04002268 init_waitqueue_head(&phba->wait_4_mlo_m_q);
James Smart2e0fef82007-06-17 19:56:36 -05002269 /*
2270 * Get all the module params for configuring this host and then
2271 * establish the host.
2272 */
2273 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002274 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002275
2276 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05002277 init_timer(&phba->hb_tmofunc);
2278 phba->hb_tmofunc.function = lpfc_hb_timeout;
2279 phba->hb_tmofunc.data = (unsigned long)phba;
2280
dea31012005-04-17 16:05:31 -05002281 psli = &phba->sli;
2282 init_timer(&psli->mbox_tmo);
2283 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002284 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002285 init_timer(&phba->fcp_poll_timer);
2286 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002287 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002288 init_timer(&phba->fabric_block_timer);
2289 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2290 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002291
dea31012005-04-17 16:05:31 -05002292 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002293 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002294
2295 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2296 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2297 goto out_idr_remove;
2298
2299 /*
2300 * Get the bus address of Bar0 and Bar2 and the number of bytes
2301 * required by each mapping.
2302 */
2303 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2304 bar0map_len = pci_resource_len(phba->pcidev, 0);
2305
2306 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2307 bar2map_len = pci_resource_len(phba->pcidev, 2);
2308
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002309 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002310 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002311 if (!phba->slim_memmap_p) {
2312 error = -ENODEV;
2313 dev_printk(KERN_ERR, &pdev->dev,
2314 "ioremap failed for SLIM memory.\n");
2315 goto out_idr_remove;
2316 }
2317
2318 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002319 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002320 if (!phba->ctrl_regs_memmap_p) {
2321 error = -ENODEV;
2322 dev_printk(KERN_ERR, &pdev->dev,
2323 "ioremap failed for HBA control registers.\n");
2324 goto out_iounmap_slim;
2325 }
dea31012005-04-17 16:05:31 -05002326
2327 /* Allocate memory for SLI-2 structures */
James Smart34b02dc2008-08-24 21:49:55 -04002328 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2329 SLI2_SLIM_SIZE,
2330 &phba->slim2p.phys,
2331 GFP_KERNEL);
2332 if (!phba->slim2p.virt)
dea31012005-04-17 16:05:31 -05002333 goto out_iounmap;
2334
James Smart34b02dc2008-08-24 21:49:55 -04002335 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
James Smartd7c255b2008-08-24 21:50:00 -04002336 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
2337 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
2338 phba->IOCBs = (phba->slim2p.virt +
2339 offsetof(struct lpfc_sli2_slim, IOCBs));
dea31012005-04-17 16:05:31 -05002340
James Smarted957682007-06-17 19:56:37 -05002341 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2342 lpfc_sli_hbq_size(),
2343 &phba->hbqslimp.phys,
2344 GFP_KERNEL);
2345 if (!phba->hbqslimp.virt)
2346 goto out_free_slim;
2347
James Smart51ef4c22007-08-02 11:10:31 -04002348 hbq_count = lpfc_sli_hbq_count();
2349 ptr = phba->hbqslimp.virt;
2350 for (i = 0; i < hbq_count; ++i) {
2351 phba->hbqs[i].hbq_virt = ptr;
2352 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2353 ptr += (lpfc_hbq_defs[i]->entry_count *
2354 sizeof(struct lpfc_hbq_entry));
2355 }
2356 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2357 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2358
James Smarted957682007-06-17 19:56:37 -05002359 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2360
James Smart3163f722008-02-08 18:50:25 -05002361 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2362
dea31012005-04-17 16:05:31 -05002363 /* Initialize the SLI Layer to run with lpfc HBAs. */
2364 lpfc_sli_setup(phba);
2365 lpfc_sli_queue_setup(phba);
2366
James Smart98c9ea52007-10-27 13:37:33 -04002367 retval = lpfc_mem_alloc(phba);
2368 if (retval) {
2369 error = retval;
James Smarted957682007-06-17 19:56:37 -05002370 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002371 }
dea31012005-04-17 16:05:31 -05002372
2373 /* Initialize and populate the iocb list per host. */
2374 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2375 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002376 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002377 if (iocbq_entry == NULL) {
2378 printk(KERN_ERR "%s: only allocated %d iocbs of "
2379 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002380 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002381 error = -ENOMEM;
2382 goto out_free_iocbq;
2383 }
2384
James Bottomley604a3e32005-10-29 10:28:33 -05002385 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2386 if (iotag == 0) {
2387 kfree (iocbq_entry);
2388 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2389 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002390 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002391 error = -ENOMEM;
2392 goto out_free_iocbq;
2393 }
James Smart2e0fef82007-06-17 19:56:36 -05002394
2395 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002396 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2397 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002398 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002399 }
2400
2401 /* Initialize HBA structure */
2402 phba->fc_edtov = FF_DEF_EDTOV;
2403 phba->fc_ratov = FF_DEF_RATOV;
2404 phba->fc_altov = FF_DEF_ALTOV;
2405 phba->fc_arbtov = FF_DEF_ARBTOV;
2406
2407 INIT_LIST_HEAD(&phba->work_list);
2408 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2409 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2410
James Smart5e9d9b82008-06-14 22:52:53 -04002411 /* Initialize the wait queue head for the kernel thread */
2412 init_waitqueue_head(&phba->work_waitq);
2413
dea31012005-04-17 16:05:31 -05002414 /* Startup the kernel thread for this host adapter. */
2415 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2416 "lpfc_worker_%d", phba->brd_no);
2417 if (IS_ERR(phba->worker_thread)) {
2418 error = PTR_ERR(phba->worker_thread);
2419 goto out_free_iocbq;
2420 }
2421
dea31012005-04-17 16:05:31 -05002422 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002423 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002424 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2425
James Smart92d7f7b2007-06-17 19:56:38 -05002426 /* Initialize list of fabric iocbs */
2427 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2428
James Smart0ff10d42008-01-11 01:52:36 -05002429 /* Initialize list to save ELS buffers */
2430 INIT_LIST_HEAD(&phba->elsbuf);
2431
James Smart3de2a652007-08-02 11:09:59 -04002432 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002433 if (!vport)
2434 goto out_kthread_stop;
2435
2436 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002437 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002438 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002439
James Smart92d7f7b2007-06-17 19:56:38 -05002440 pci_set_drvdata(pdev, shost);
James Smartdb2378e2008-02-08 18:49:51 -05002441 phba->intr_type = NONE;
dea31012005-04-17 16:05:31 -05002442
James Smartdb2378e2008-02-08 18:49:51 -05002443 if (phba->cfg_use_msi == 2) {
2444 error = lpfc_enable_msix(phba);
2445 if (!error)
2446 phba->intr_type = MSIX;
2447 }
2448
2449 /* Fallback to MSI if MSI-X initialization failed */
2450 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
James Smart98c9ea52007-10-27 13:37:33 -04002451 retval = pci_enable_msi(phba->pcidev);
2452 if (!retval)
James Smartdb2378e2008-02-08 18:49:51 -05002453 phba->intr_type = MSI;
James Smart51ef4c22007-08-02 11:10:31 -04002454 else
James Smarte8b62012007-08-02 11:10:09 -04002455 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2456 "0452 Enable MSI failed, continuing "
2457 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002458 }
2459
James Smartdb2378e2008-02-08 18:49:51 -05002460 /* MSI-X is the only case the doesn't need to call request_irq */
2461 if (phba->intr_type != MSIX) {
2462 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2463 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2464 if (retval) {
2465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2466 "interrupt handler failed\n");
2467 error = retval;
2468 goto out_disable_msi;
2469 } else if (phba->intr_type != MSI)
2470 phba->intr_type = INTx;
dea31012005-04-17 16:05:31 -05002471 }
dea31012005-04-17 16:05:31 -05002472
James Smart2e0fef82007-06-17 19:56:36 -05002473 phba->MBslimaddr = phba->slim_memmap_p;
2474 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2475 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2476 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2477 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2478
James Smart98c9ea52007-10-27 13:37:33 -04002479 if (lpfc_alloc_sysfs_attr(vport)) {
2480 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002481 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002482 }
dea31012005-04-17 16:05:31 -05002483
James Smart98c9ea52007-10-27 13:37:33 -04002484 if (lpfc_sli_hba_setup(phba)) {
2485 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002486 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002487 }
James Smart858c9f62007-06-17 19:56:39 -05002488
2489 /*
2490 * hba setup may have changed the hba_queue_depth so we need to adjust
2491 * the value of can_queue.
2492 */
2493 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2494
2495 lpfc_host_attrib_init(shost);
2496
James Smart2e0fef82007-06-17 19:56:36 -05002497 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2498 spin_lock_irq(shost->host_lock);
2499 lpfc_poll_start_timer(phba);
2500 spin_unlock_irq(shost->host_lock);
2501 }
James Smart8f6d98d2006-08-01 07:34:00 -04002502
James Smart858c9f62007-06-17 19:56:39 -05002503 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002504
dea31012005-04-17 16:05:31 -05002505 return 0;
2506
James Smart858c9f62007-06-17 19:56:39 -05002507out_remove_device:
2508 lpfc_free_sysfs_attr(vport);
2509 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002510 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002511 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002512out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002513 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002514 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002515
2516 if (phba->intr_type == MSIX)
2517 lpfc_disable_msix(phba);
2518 else
2519 free_irq(phba->pcidev->irq, phba);
2520
James Smart92d7f7b2007-06-17 19:56:38 -05002521out_disable_msi:
James Smartdb2378e2008-02-08 18:49:51 -05002522 if (phba->intr_type == MSI)
James Smart51ef4c22007-08-02 11:10:31 -04002523 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002524 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002525out_kthread_stop:
2526 kthread_stop(phba->worker_thread);
2527out_free_iocbq:
2528 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2529 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002530 kfree(iocbq_entry);
2531 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002532 }
2533 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002534out_free_hbqslimp:
James Smart34b02dc2008-08-24 21:49:55 -04002535 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2536 phba->hbqslimp.virt, phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002537out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04002538 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2539 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05002540out_iounmap:
2541 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002542out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002543 iounmap(phba->slim_memmap_p);
2544out_idr_remove:
2545 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002546out_free_phba:
2547 kfree(phba);
dea31012005-04-17 16:05:31 -05002548out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002549 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002550out_disable_device:
2551 pci_disable_device(pdev);
2552out:
James Smartdefbcf12006-04-16 22:26:50 -04002553 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002554 if (shost)
2555 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002556 return error;
2557}
2558
James Smarte59058c2008-08-24 21:49:00 -04002559/**
2560 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2561 * @pdev: pointer to PCI device
2562 *
2563 * This routine is to be registered to the kernel's PCI subsystem. When an
2564 * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup
2565 * for the HBA device to be removed from the PCI subsystem properly.
2566 **/
dea31012005-04-17 16:05:31 -05002567static void __devexit
2568lpfc_pci_remove_one(struct pci_dev *pdev)
2569{
James Smart2e0fef82007-06-17 19:56:36 -05002570 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2571 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2572 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002573 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2574
James Smart549e55c2007-08-02 11:09:51 -04002575 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002576 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002577 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002578
James Smart858c9f62007-06-17 19:56:39 -05002579 kfree(vport->vname);
2580 lpfc_free_sysfs_attr(vport);
2581
James Smart09372822008-01-11 01:52:54 -05002582 kthread_stop(phba->worker_thread);
2583
James Smart858c9f62007-06-17 19:56:39 -05002584 fc_remove_host(shost);
2585 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002586 lpfc_cleanup(vport);
2587
James Smart2e0fef82007-06-17 19:56:36 -05002588 /*
2589 * Bring down the SLI Layer. This step disable all interrupts,
2590 * clears the rings, discards all mailbox commands, and resets
2591 * the HBA.
2592 */
2593 lpfc_sli_hba_down(phba);
2594 lpfc_sli_brdrestart(phba);
2595
James Smart92d7f7b2007-06-17 19:56:38 -05002596 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002597 spin_lock_irq(&phba->hbalock);
2598 list_del_init(&vport->listentry);
2599 spin_unlock_irq(&phba->hbalock);
2600
James Smart858c9f62007-06-17 19:56:39 -05002601 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002602
James Smartdb2378e2008-02-08 18:49:51 -05002603 if (phba->intr_type == MSIX)
2604 lpfc_disable_msix(phba);
2605 else {
2606 free_irq(phba->pcidev->irq, phba);
2607 if (phba->intr_type == MSI)
2608 pci_disable_msi(phba->pcidev);
2609 }
dea31012005-04-17 16:05:31 -05002610
2611 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002612 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002613
2614 /*
2615 * Call scsi_free before mem_free since scsi bufs are released to their
2616 * corresponding pools here.
2617 */
2618 lpfc_scsi_free(phba);
2619 lpfc_mem_free(phba);
2620
James Smart34b02dc2008-08-24 21:49:55 -04002621 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2622 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05002623
James Smart2e0fef82007-06-17 19:56:36 -05002624 /* Free resources associated with SLI2 interface */
2625 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04002626 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05002627
2628 /* unmap adapter SLIM and Control Registers */
2629 iounmap(phba->ctrl_regs_memmap_p);
2630 iounmap(phba->slim_memmap_p);
2631
2632 idr_remove(&lpfc_hba_index, phba->brd_no);
2633
2634 kfree(phba);
2635
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002636 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002637 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002638}
2639
Linas Vepstas8d63f372007-02-14 14:28:36 -06002640/**
James Smarte59058c2008-08-24 21:49:00 -04002641 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
2642 * @pdev: pointer to PCI device.
2643 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002644 *
James Smarte59058c2008-08-24 21:49:00 -04002645 * This routine is registered to the PCI subsystem for error handling. This
2646 * function is called by the PCI subsystem after a PCI bus error affecting
2647 * this device has been detected. When this function is invoked, it will
2648 * need to stop all the I/Os and interrupt(s) to the device. Once that is
2649 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
2650 * perform proper recovery as desired.
2651 *
2652 * Return codes
2653 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
2654 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2655 **/
Linas Vepstas8d63f372007-02-14 14:28:36 -06002656static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2657 pci_channel_state_t state)
2658{
James Smart51ef4c22007-08-02 11:10:31 -04002659 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2660 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002661 struct lpfc_sli *psli = &phba->sli;
2662 struct lpfc_sli_ring *pring;
2663
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002664 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002665 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002666
Linas Vepstas8d63f372007-02-14 14:28:36 -06002667 pci_disable_device(pdev);
2668 /*
2669 * There may be I/Os dropped by the firmware.
2670 * Error iocb (I/O) on txcmplq and let the SCSI layer
2671 * retry it after re-establishing link.
2672 */
2673 pring = &psli->ring[psli->fcp_ring];
2674 lpfc_sli_abort_iocb_ring(phba, pring);
2675
James Smartdb2378e2008-02-08 18:49:51 -05002676 if (phba->intr_type == MSIX)
2677 lpfc_disable_msix(phba);
2678 else {
2679 free_irq(phba->pcidev->irq, phba);
2680 if (phba->intr_type == MSI)
2681 pci_disable_msi(phba->pcidev);
2682 }
James Smart51ef4c22007-08-02 11:10:31 -04002683
Linas Vepstas8d63f372007-02-14 14:28:36 -06002684 /* Request a slot reset. */
2685 return PCI_ERS_RESULT_NEED_RESET;
2686}
2687
2688/**
James Smarte59058c2008-08-24 21:49:00 -04002689 * lpfc_io_slot_reset: Restart a PCI device from scratch.
2690 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002691 *
James Smarte59058c2008-08-24 21:49:00 -04002692 * This routine is registered to the PCI subsystem for error handling. This is
2693 * called after PCI bus has been reset to restart the PCI card from scratch,
2694 * as if from a cold-boot. During the PCI subsystem error recovery, after the
2695 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
2696 * proper error recovery and then call this routine before calling the .resume
2697 * method to recover the device. This function will initialize the HBA device,
2698 * enable the interrupt, but it will just put the HBA to offline state without
2699 * passing any I/O traffic.
2700 *
2701 * Return codes
2702 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
2703 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06002704 */
2705static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2706{
James Smart51ef4c22007-08-02 11:10:31 -04002707 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2708 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002709 struct lpfc_sli *psli = &phba->sli;
James Smart9b379602008-04-07 10:16:00 -04002710 int error, retval;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002711
2712 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002713 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002714 printk(KERN_ERR "lpfc: Cannot re-enable "
2715 "PCI device after reset.\n");
2716 return PCI_ERS_RESULT_DISCONNECT;
2717 }
2718
2719 pci_set_master(pdev);
2720
James Smart92d7f7b2007-06-17 19:56:38 -05002721 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002722 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002723 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002724
James Smart9b379602008-04-07 10:16:00 -04002725 /* Enable configured interrupt method */
2726 phba->intr_type = NONE;
2727 if (phba->cfg_use_msi == 2) {
2728 error = lpfc_enable_msix(phba);
2729 if (!error)
2730 phba->intr_type = MSIX;
2731 }
2732
2733 /* Fallback to MSI if MSI-X initialization failed */
2734 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2735 retval = pci_enable_msi(phba->pcidev);
2736 if (!retval)
2737 phba->intr_type = MSI;
2738 else
2739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2740 "0470 Enable MSI failed, continuing "
2741 "with IRQ\n");
2742 }
2743
2744 /* MSI-X is the only case the doesn't need to call request_irq */
2745 if (phba->intr_type != MSIX) {
2746 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2747 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2748 if (retval) {
2749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2750 "0471 Enable interrupt handler "
2751 "failed\n");
2752 } else if (phba->intr_type != MSI)
2753 phba->intr_type = INTx;
2754 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06002755
2756 /* Take device offline; this will perform cleanup */
2757 lpfc_offline(phba);
2758 lpfc_sli_brdrestart(phba);
2759
2760 return PCI_ERS_RESULT_RECOVERED;
2761}
2762
2763/**
James Smarte59058c2008-08-24 21:49:00 -04002764 * lpfc_io_resume: Resume PCI I/O operation.
2765 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06002766 *
James Smarte59058c2008-08-24 21:49:00 -04002767 * This routine is registered to the PCI subsystem for error handling. It is
2768 * called when kernel error recovery tells the lpfc driver that it is ok to
2769 * resume normal PCI operation after PCI bus error recovery. After this call,
2770 * traffic can start to flow from this device again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06002771 */
2772static void lpfc_io_resume(struct pci_dev *pdev)
2773{
James Smart51ef4c22007-08-02 11:10:31 -04002774 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2775 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002776
James Smart58da1ff2008-04-07 10:15:56 -04002777 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002778}
2779
dea31012005-04-17 16:05:31 -05002780static struct pci_device_id lpfc_id_table[] = {
2781 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2782 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002783 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2784 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002785 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2786 PCI_ANY_ID, PCI_ANY_ID, },
2787 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2788 PCI_ANY_ID, PCI_ANY_ID, },
2789 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2790 PCI_ANY_ID, PCI_ANY_ID, },
2791 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2792 PCI_ANY_ID, PCI_ANY_ID, },
2793 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2794 PCI_ANY_ID, PCI_ANY_ID, },
2795 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2796 PCI_ANY_ID, PCI_ANY_ID, },
2797 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2798 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002799 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2800 PCI_ANY_ID, PCI_ANY_ID, },
2801 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2802 PCI_ANY_ID, PCI_ANY_ID, },
2803 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2804 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002805 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2806 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002807 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2808 PCI_ANY_ID, PCI_ANY_ID, },
2809 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2810 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002811 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2812 PCI_ANY_ID, PCI_ANY_ID, },
2813 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2814 PCI_ANY_ID, PCI_ANY_ID, },
2815 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2816 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04002817 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
2818 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002819 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2820 PCI_ANY_ID, PCI_ANY_ID, },
2821 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2822 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002823 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2824 PCI_ANY_ID, PCI_ANY_ID, },
2825 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2826 PCI_ANY_ID, PCI_ANY_ID, },
2827 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2828 PCI_ANY_ID, PCI_ANY_ID, },
2829 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2830 PCI_ANY_ID, PCI_ANY_ID, },
2831 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2832 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002833 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2834 PCI_ANY_ID, PCI_ANY_ID, },
2835 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2836 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002837 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2838 PCI_ANY_ID, PCI_ANY_ID, },
2839 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2840 PCI_ANY_ID, PCI_ANY_ID, },
2841 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2842 PCI_ANY_ID, PCI_ANY_ID, },
2843 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2844 PCI_ANY_ID, PCI_ANY_ID, },
2845 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2846 PCI_ANY_ID, PCI_ANY_ID, },
2847 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2848 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04002849 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
2850 PCI_ANY_ID, PCI_ANY_ID, },
2851 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
2852 PCI_ANY_ID, PCI_ANY_ID, },
2853 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
2854 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002855 { 0 }
2856};
2857
2858MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2859
Linas Vepstas8d63f372007-02-14 14:28:36 -06002860static struct pci_error_handlers lpfc_err_handler = {
2861 .error_detected = lpfc_io_error_detected,
2862 .slot_reset = lpfc_io_slot_reset,
2863 .resume = lpfc_io_resume,
2864};
2865
dea31012005-04-17 16:05:31 -05002866static struct pci_driver lpfc_driver = {
2867 .name = LPFC_DRIVER_NAME,
2868 .id_table = lpfc_id_table,
2869 .probe = lpfc_pci_probe_one,
2870 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002871 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002872};
2873
James Smarte59058c2008-08-24 21:49:00 -04002874/**
2875 * lpfc_init: lpfc module initialization routine.
2876 *
2877 * This routine is to be invoked when the lpfc module is loaded into the
2878 * kernel. The special kernel macro module_init() is used to indicate the
2879 * role of this routine to the kernel as lpfc module entry point.
2880 *
2881 * Return codes
2882 * 0 - successful
2883 * -ENOMEM - FC attach transport failed
2884 * all others - failed
2885 */
dea31012005-04-17 16:05:31 -05002886static int __init
2887lpfc_init(void)
2888{
2889 int error = 0;
2890
2891 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002892 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002893
James Smart7ee5d432007-10-27 13:37:17 -04002894 if (lpfc_enable_npiv) {
2895 lpfc_transport_functions.vport_create = lpfc_vport_create;
2896 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2897 }
dea31012005-04-17 16:05:31 -05002898 lpfc_transport_template =
2899 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002900 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002901 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002902 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002903 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002904 fc_attach_transport(&lpfc_vport_transport_functions);
2905 if (lpfc_vport_transport_template == NULL) {
2906 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002907 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002908 }
James Smart7ee5d432007-10-27 13:37:17 -04002909 }
dea31012005-04-17 16:05:31 -05002910 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002911 if (error) {
dea31012005-04-17 16:05:31 -05002912 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04002913 if (lpfc_enable_npiv)
2914 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002915 }
dea31012005-04-17 16:05:31 -05002916
2917 return error;
2918}
2919
James Smarte59058c2008-08-24 21:49:00 -04002920/**
2921 * lpfc_exit: lpfc module removal routine.
2922 *
2923 * This routine is invoked when the lpfc module is removed from the kernel.
2924 * The special kernel macro module_exit() is used to indicate the role of
2925 * this routine to the kernel as lpfc module exit point.
2926 */
dea31012005-04-17 16:05:31 -05002927static void __exit
2928lpfc_exit(void)
2929{
2930 pci_unregister_driver(&lpfc_driver);
2931 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002932 if (lpfc_enable_npiv)
2933 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002934}
2935
2936module_init(lpfc_init);
2937module_exit(lpfc_exit);
2938MODULE_LICENSE("GPL");
2939MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2940MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2941MODULE_VERSION("0:" LPFC_DRIVER_VERSION);