blob: d51a2a4b43eb662f61a6603a21b3b5feb2337385 [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
55/************************************************************************/
56/* */
57/* lpfc_config_port_prep */
58/* This routine will do LPFC initialization prior to the */
59/* CONFIG_PORT mailbox command. This will be initialized */
60/* as a SLI layer callback routine. */
61/* This routine returns 0 on success or -ERESTART if it wants */
62/* the SLI layer to reset the HBA and try again. Any */
63/* other return value indicates an error. */
64/* */
65/************************************************************************/
66int
James Smart2e0fef82007-06-17 19:56:36 -050067lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050068{
69 lpfc_vpd_t *vp = &phba->vpd;
70 int i = 0, rc;
71 LPFC_MBOXQ_t *pmb;
72 MAILBOX_t *mb;
73 char *lpfc_vpd_data = NULL;
74 uint16_t offset = 0;
75 static char licensed[56] =
76 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040077 static int init_key = 1;
dea31012005-04-17 16:05:31 -050078
79 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
80 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050081 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050082 return -ENOMEM;
83 }
84
85 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050086 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050087
88 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040089 if (init_key) {
90 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050091
James Smart65a29c12006-07-06 15:50:50 -040092 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
93 *ptext = cpu_to_be32(*ptext);
94 init_key = 0;
95 }
dea31012005-04-17 16:05:31 -050096
97 lpfc_read_nv(phba, pmb);
98 memset((char*)mb->un.varRDnvp.rsvd3, 0,
99 sizeof (mb->un.varRDnvp.rsvd3));
100 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
101 sizeof (licensed));
102
103 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
104
105 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500106 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400107 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500108 "error, mbxCmd x%x READ_NVPARM, "
109 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500110 mb->mbxCommand, mb->mbxStatus);
111 mempool_free(pmb, phba->mbox_mem_pool);
112 return -ERESTART;
113 }
114 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500115 sizeof(phba->wwnn));
116 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
117 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500118 }
119
James Smart92d7f7b2007-06-17 19:56:38 -0500120 phba->sli3_options = 0x0;
121
dea31012005-04-17 16:05:31 -0500122 /* Setup and issue mailbox READ REV command */
123 lpfc_read_rev(phba, pmb);
124 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
125 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400127 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500128 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500129 mb->mbxCommand, mb->mbxStatus);
130 mempool_free( pmb, phba->mbox_mem_pool);
131 return -ERESTART;
132 }
133
James Smart92d7f7b2007-06-17 19:56:38 -0500134
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500135 /*
136 * The value of rr must be 1 since the driver set the cv field to 1.
137 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500138 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500139 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500140 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400142 "0440 Adapter failed to init, READ_REV has "
143 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500144 mempool_free(pmb, phba->mbox_mem_pool);
145 return -ERESTART;
dea31012005-04-17 16:05:31 -0500146 }
147
James Smart495a7142008-06-14 22:52:59 -0400148 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
149 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500150 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400151 }
James Smarted957682007-06-17 19:56:37 -0500152
dea31012005-04-17 16:05:31 -0500153 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500154 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500155 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500156 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
157 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
158 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
159 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500160 vp->rev.biuRev = mb->un.varRdRev.biuRev;
161 vp->rev.smRev = mb->un.varRdRev.smRev;
162 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
163 vp->rev.endecRev = mb->un.varRdRev.endecRev;
164 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
165 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
166 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
167 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
168 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
169 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
170
James Smart92d7f7b2007-06-17 19:56:38 -0500171 /* If the sli feature level is less then 9, we must
172 * tear down all RPIs and VPIs on link down if NPIV
173 * is enabled.
174 */
175 if (vp->rev.feaLevelHigh < 9)
176 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
177
dea31012005-04-17 16:05:31 -0500178 if (lpfc_is_LC_HBA(phba->pcidev->device))
179 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
180 sizeof (phba->RandomData));
181
dea31012005-04-17 16:05:31 -0500182 /* Get adapter VPD information */
183 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
184 if (!pmb->context2)
185 goto out_free_mbox;
186 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
187 if (!lpfc_vpd_data)
188 goto out_free_context2;
189
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;
dea31012005-04-17 16:05:31 -0500203 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500204 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500205 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500206 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
207 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500208
209 kfree(lpfc_vpd_data);
210out_free_context2:
211 kfree(pmb->context2);
212out_free_mbox:
213 mempool_free(pmb, phba->mbox_mem_pool);
214 return 0;
215}
216
James Smart57127f12007-10-27 13:37:05 -0400217/* Completion handler for config async event mailbox command. */
218static void
219lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
220{
221 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
222 phba->temp_sensor_support = 1;
223 else
224 phba->temp_sensor_support = 0;
225 mempool_free(pmboxq, phba->mbox_mem_pool);
226 return;
227}
228
dea31012005-04-17 16:05:31 -0500229/************************************************************************/
230/* */
231/* lpfc_config_port_post */
232/* This routine will do LPFC initialization after the */
233/* CONFIG_PORT mailbox command. This will be initialized */
234/* as a SLI layer callback routine. */
235/* This routine returns 0 on success. Any other return value */
236/* indicates an error. */
237/* */
238/************************************************************************/
239int
James Smart2e0fef82007-06-17 19:56:36 -0500240lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500241{
James Smart2e0fef82007-06-17 19:56:36 -0500242 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500243 LPFC_MBOXQ_t *pmb;
244 MAILBOX_t *mb;
245 struct lpfc_dmabuf *mp;
246 struct lpfc_sli *psli = &phba->sli;
247 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500248 int i, j;
249 int rc;
dea31012005-04-17 16:05:31 -0500250
James Smart7af67052007-10-27 13:38:11 -0400251 spin_lock_irq(&phba->hbalock);
252 /*
253 * If the Config port completed correctly the HBA is not
254 * over heated any more.
255 */
256 if (phba->over_temp_state == HBA_OVER_TEMP)
257 phba->over_temp_state = HBA_NORMAL_TEMP;
258 spin_unlock_irq(&phba->hbalock);
259
dea31012005-04-17 16:05:31 -0500260 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
261 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500262 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500263 return -ENOMEM;
264 }
265 mb = &pmb->mb;
266
dea31012005-04-17 16:05:31 -0500267 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500268 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500269 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500270 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400272 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500273 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500274 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500275 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500276 mp = (struct lpfc_dmabuf *) pmb->context1;
277 mempool_free( pmb, phba->mbox_mem_pool);
278 lpfc_mbuf_free(phba, mp->virt, mp->phys);
279 kfree(mp);
280 return -EIO;
281 }
282
283 mp = (struct lpfc_dmabuf *) pmb->context1;
284
James Smart2e0fef82007-06-17 19:56:36 -0500285 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500286 lpfc_mbuf_free(phba, mp->virt, mp->phys);
287 kfree(mp);
288 pmb->context1 = NULL;
289
James Smarta12e07b2006-12-02 13:35:30 -0500290 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500291 u64_to_wwn(phba->cfg_soft_wwnn,
292 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400293 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500294 u64_to_wwn(phba->cfg_soft_wwpn,
295 vport->fc_sparam.portName.u.wwn);
296 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500297 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500298 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500299 sizeof (struct lpfc_name));
300 /* If no serial number in VPD data, use low 6 bytes of WWNN */
301 /* This should be consolidated into parse_vpd ? - mr */
302 if (phba->SerialNumber[0] == 0) {
303 uint8_t *outptr;
304
James Smart2e0fef82007-06-17 19:56:36 -0500305 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500306 for (i = 0; i < 12; i++) {
307 status = *outptr++;
308 j = ((status & 0xf0) >> 4);
309 if (j <= 9)
310 phba->SerialNumber[i] =
311 (char)((uint8_t) 0x30 + (uint8_t) j);
312 else
313 phba->SerialNumber[i] =
314 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
315 i++;
316 j = (status & 0xf);
317 if (j <= 9)
318 phba->SerialNumber[i] =
319 (char)((uint8_t) 0x30 + (uint8_t) j);
320 else
321 phba->SerialNumber[i] =
322 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
323 }
324 }
325
dea31012005-04-17 16:05:31 -0500326 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500327 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500328 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500329 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400330 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500331 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500332 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500333 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500334 mempool_free( pmb, phba->mbox_mem_pool);
335 return -EIO;
336 }
337
338 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
339 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
340 phba->cfg_hba_queue_depth =
341 mb->un.varRdConfig.max_xri + 1;
342
343 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500344
345 /* Get the default values for Model Name and Description */
346 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
347
348 if ((phba->cfg_link_speed > LINK_SPEED_10G)
349 || ((phba->cfg_link_speed == LINK_SPEED_1G)
350 && !(phba->lmt & LMT_1Gb))
351 || ((phba->cfg_link_speed == LINK_SPEED_2G)
352 && !(phba->lmt & LMT_2Gb))
353 || ((phba->cfg_link_speed == LINK_SPEED_4G)
354 && !(phba->lmt & LMT_4Gb))
355 || ((phba->cfg_link_speed == LINK_SPEED_8G)
356 && !(phba->lmt & LMT_8Gb))
357 || ((phba->cfg_link_speed == LINK_SPEED_10G)
358 && !(phba->lmt & LMT_10Gb))) {
359 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500360 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400361 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500362 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500363 phba->cfg_link_speed);
364 phba->cfg_link_speed = LINK_SPEED_AUTO;
365 }
366
James Smart2e0fef82007-06-17 19:56:36 -0500367 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500368
James Smart0b727fe2007-10-27 13:37:25 -0400369 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500370 if (psli->ring[psli->extra_ring].cmdringaddr)
371 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500372 if (psli->ring[psli->fcp_ring].cmdringaddr)
373 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
374 if (psli->ring[psli->next_ring].cmdringaddr)
375 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
376
377 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500378 if (phba->sli_rev != 3)
379 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500380
381 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500382 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500383 status = readl(phba->HCregaddr);
384 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
385 if (psli->num_rings > 0)
386 status |= HC_R0INT_ENA;
387 if (psli->num_rings > 1)
388 status |= HC_R1INT_ENA;
389 if (psli->num_rings > 2)
390 status |= HC_R2INT_ENA;
391 if (psli->num_rings > 3)
392 status |= HC_R3INT_ENA;
393
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500394 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
395 (phba->cfg_poll & DISABLE_FCP_RING_INT))
396 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
397
dea31012005-04-17 16:05:31 -0500398 writel(status, phba->HCregaddr);
399 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500400 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500401
402 /*
403 * Setup the ring 0 (els) timeout handler
404 */
405 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500406 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500407 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
408 phba->hb_outstanding = 0;
409 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500410
411 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
412 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500413 pmb->vport = vport;
James Smart8aee9182006-08-31 12:27:57 -0400414 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400415 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400416 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400418 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500419 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500420 mb->mbxCommand, mb->mbxStatus);
421
422 /* Clear all interrupt enable conditions */
423 writel(0, phba->HCregaddr);
424 readl(phba->HCregaddr); /* flush */
425 /* Clear all pending interrupts */
426 writel(0xffffffff, phba->HAregaddr);
427 readl(phba->HAregaddr); /* flush */
428
James Smart2e0fef82007-06-17 19:56:36 -0500429 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400430 if (rc != MBX_BUSY)
431 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500432 return -EIO;
433 }
434 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400435 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
436 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
437 pmb->mbox_cmpl = lpfc_config_async_cmpl;
438 pmb->vport = phba->pport;
439 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500440
James Smart57127f12007-10-27 13:37:05 -0400441 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
442 lpfc_printf_log(phba,
443 KERN_ERR,
444 LOG_INIT,
445 "0456 Adapter failed to issue "
446 "ASYNCEVT_ENABLE mbox status x%x \n.",
447 rc);
448 mempool_free(pmb, phba->mbox_mem_pool);
449 }
James Smartce8b3ce2006-07-06 15:50:36 -0400450 return (0);
451}
452
dea31012005-04-17 16:05:31 -0500453/************************************************************************/
454/* */
455/* lpfc_hba_down_prep */
456/* This routine will do LPFC uninitialization before the */
457/* HBA is reset when bringing down the SLI Layer. This will be */
458/* initialized as a SLI layer callback routine. */
459/* This routine returns 0 on success. Any other return value */
460/* indicates an error. */
461/* */
462/************************************************************************/
463int
James Smart2e0fef82007-06-17 19:56:36 -0500464lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500465{
James Smart1b32f6a2008-02-08 18:49:39 -0500466 struct lpfc_vport **vports;
467 int i;
dea31012005-04-17 16:05:31 -0500468 /* Disable interrupts */
469 writel(0, phba->HCregaddr);
470 readl(phba->HCregaddr); /* flush */
471
James Smart1b32f6a2008-02-08 18:49:39 -0500472 if (phba->pport->load_flag & FC_UNLOADING)
473 lpfc_cleanup_discovery_resources(phba->pport);
474 else {
475 vports = lpfc_create_vport_work_array(phba);
476 if (vports != NULL)
477 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
478 lpfc_cleanup_discovery_resources(vports[i]);
479 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500480 }
481 return 0;
dea31012005-04-17 16:05:31 -0500482}
483
484/************************************************************************/
485/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500486/* lpfc_hba_down_post */
487/* This routine will do uninitialization after the HBA is reset */
488/* when bringing down the SLI Layer. */
489/* This routine returns 0 on success. Any other return value */
490/* indicates an error. */
491/* */
492/************************************************************************/
493int
James Smart2e0fef82007-06-17 19:56:36 -0500494lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500495{
496 struct lpfc_sli *psli = &phba->sli;
497 struct lpfc_sli_ring *pring;
498 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500499 struct lpfc_iocbq *iocb;
500 IOCB_t *cmd = NULL;
501 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500502 int i;
503
James Smart92d7f7b2007-06-17 19:56:38 -0500504 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
505 lpfc_sli_hbqbuf_free_all(phba);
506 else {
507 /* Cleanup preposted buffers on the ELS ring */
508 pring = &psli->ring[LPFC_ELS_RING];
509 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
510 list_del(&mp->list);
511 pring->postbufq_cnt--;
512 lpfc_mbuf_free(phba, mp->virt, mp->phys);
513 kfree(mp);
514 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500515 }
516
James Smart09372822008-01-11 01:52:54 -0500517 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500518 for (i = 0; i < psli->num_rings; i++) {
519 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500520
521 /* At this point in time the HBA is either reset or DOA. Either
522 * way, nothing should be on txcmplq as it will NEVER complete.
523 */
524 list_splice_init(&pring->txcmplq, &completions);
525 pring->txcmplq_cnt = 0;
526 spin_unlock_irq(&phba->hbalock);
527
528 while (!list_empty(&completions)) {
529 iocb = list_get_first(&completions, struct lpfc_iocbq,
530 list);
531 cmd = &iocb->iocb;
532 list_del_init(&iocb->list);
533
534 if (!iocb->iocb_cmpl)
535 lpfc_sli_release_iocbq(phba, iocb);
536 else {
537 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
538 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
539 (iocb->iocb_cmpl) (phba, iocb, iocb);
540 }
541 }
542
Jamie Wellnitz41415862006-02-28 19:25:27 -0500543 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500544 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500545 }
James Smart09372822008-01-11 01:52:54 -0500546 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500547
548 return 0;
549}
550
James Smart858c9f62007-06-17 19:56:39 -0500551/* HBA heart beat timeout handler */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100552static void
James Smart858c9f62007-06-17 19:56:39 -0500553lpfc_hb_timeout(unsigned long ptr)
554{
555 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400556 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500557 unsigned long iflag;
558
559 phba = (struct lpfc_hba *)ptr;
560 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400561 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
562 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500563 phba->pport->work_port_events |= WORKER_HB_TMO;
564 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
565
James Smart5e9d9b82008-06-14 22:52:53 -0400566 if (!tmo_posted)
567 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500568 return;
569}
570
571static void
572lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
573{
574 unsigned long drvr_flag;
575
576 spin_lock_irqsave(&phba->hbalock, drvr_flag);
577 phba->hb_outstanding = 0;
578 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
579
580 mempool_free(pmboxq, phba->mbox_mem_pool);
581 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
582 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400583 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500584 mod_timer(&phba->hb_tmofunc,
585 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
586 return;
587}
588
589void
590lpfc_hb_timeout_handler(struct lpfc_hba *phba)
591{
592 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500593 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500594 int retval;
595 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500596 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500597
598 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400599 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500600 (phba->pport->fc_flag & FC_OFFLINE_MODE))
601 return;
602
603 spin_lock_irq(&phba->pport->work_port_lock);
604 /* If the timer is already canceled do nothing */
605 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
606 spin_unlock_irq(&phba->pport->work_port_lock);
607 return;
608 }
609
610 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
611 jiffies)) {
612 spin_unlock_irq(&phba->pport->work_port_lock);
613 if (!phba->hb_outstanding)
614 mod_timer(&phba->hb_tmofunc,
615 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
616 else
617 mod_timer(&phba->hb_tmofunc,
618 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
619 return;
620 }
621 spin_unlock_irq(&phba->pport->work_port_lock);
622
James Smart0ff10d42008-01-11 01:52:36 -0500623 if (phba->elsbuf_cnt &&
624 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
625 spin_lock_irq(&phba->hbalock);
626 list_splice_init(&phba->elsbuf, &completions);
627 phba->elsbuf_cnt = 0;
628 phba->elsbuf_prev_cnt = 0;
629 spin_unlock_irq(&phba->hbalock);
630
631 while (!list_empty(&completions)) {
632 list_remove_head(&completions, buf_ptr,
633 struct lpfc_dmabuf, list);
634 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
635 kfree(buf_ptr);
636 }
637 }
638 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
639
James Smart858c9f62007-06-17 19:56:39 -0500640 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500641 if (phba->cfg_enable_hba_heartbeat) {
642 if (!phba->hb_outstanding) {
643 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
644 if (!pmboxq) {
645 mod_timer(&phba->hb_tmofunc,
646 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
647 return;
648 }
649
650 lpfc_heart_beat(phba, pmboxq);
651 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
652 pmboxq->vport = phba->pport;
653 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
654
655 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
656 mempool_free(pmboxq, phba->mbox_mem_pool);
657 mod_timer(&phba->hb_tmofunc,
658 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
659 return;
660 }
James Smart858c9f62007-06-17 19:56:39 -0500661 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500662 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
663 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500664 return;
James Smart13815c82008-01-11 01:52:48 -0500665 } else {
666 /*
667 * If heart beat timeout called with hb_outstanding set
668 * we need to take the HBA offline.
669 */
670 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
671 "0459 Adapter heartbeat failure, "
672 "taking this port offline.\n");
673
674 spin_lock_irq(&phba->hbalock);
675 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
676 spin_unlock_irq(&phba->hbalock);
677
678 lpfc_offline_prep(phba);
679 lpfc_offline(phba);
680 lpfc_unblock_mgmt_io(phba);
681 phba->link_state = LPFC_HBA_ERROR;
682 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500683 }
James Smart858c9f62007-06-17 19:56:39 -0500684 }
685}
686
James Smart09372822008-01-11 01:52:54 -0500687static void
688lpfc_offline_eratt(struct lpfc_hba *phba)
689{
690 struct lpfc_sli *psli = &phba->sli;
691
692 spin_lock_irq(&phba->hbalock);
693 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
694 spin_unlock_irq(&phba->hbalock);
695 lpfc_offline_prep(phba);
696
697 lpfc_offline(phba);
698 lpfc_reset_barrier(phba);
699 lpfc_sli_brdreset(phba);
700 lpfc_hba_down_post(phba);
701 lpfc_sli_brdready(phba, HS_MBRDY);
702 lpfc_unblock_mgmt_io(phba);
703 phba->link_state = LPFC_HBA_ERROR;
704 return;
705}
706
Jamie Wellnitz41415862006-02-28 19:25:27 -0500707/************************************************************************/
708/* */
dea31012005-04-17 16:05:31 -0500709/* lpfc_handle_eratt */
710/* This routine will handle processing a Host Attention */
711/* Error Status event. This will be initialized */
712/* as a SLI layer callback routine. */
713/* */
714/************************************************************************/
715void
James Smart2e0fef82007-06-17 19:56:36 -0500716lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500717{
James Smart2e0fef82007-06-17 19:56:36 -0500718 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500719 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500720 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400721 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400722 unsigned long temperature;
723 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500724 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -0500725
Linas Vepstas8d63f372007-02-14 14:28:36 -0600726 /* If the pci channel is offline, ignore possible errors,
727 * since we cannot communicate with the pci card anyway. */
728 if (pci_channel_offline(phba->pcidev))
729 return;
James Smart13815c82008-01-11 01:52:48 -0500730 /* If resets are disabled then leave the HBA alone and return */
731 if (!phba->cfg_enable_hba_reset)
732 return;
dea31012005-04-17 16:05:31 -0500733
James Smart97eab632008-04-07 10:16:05 -0400734 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500735 /* Re-establishing Link */
736 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400737 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500738 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400739 phba->work_hs,
dea31012005-04-17 16:05:31 -0500740 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400741
James Smart92d7f7b2007-06-17 19:56:38 -0500742 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500743 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500744 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500745
746 /*
747 * Firmware stops when it triggled erratt with HS_FFER6.
748 * That could cause the I/Os dropped by the firmware.
749 * Error iocb (I/O) on txcmplq and let the SCSI layer
750 * retry it after re-establishing link.
751 */
752 pring = &psli->ring[psli->fcp_ring];
753 lpfc_sli_abort_iocb_ring(phba, pring);
754
dea31012005-04-17 16:05:31 -0500755 /*
756 * There was a firmware error. Take the hba offline and then
757 * attempt to restart it.
758 */
James Smart46fa3112007-04-25 09:51:45 -0400759 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500760 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500761 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500762 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400763 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500764 return;
765 }
James Smart46fa3112007-04-25 09:51:45 -0400766 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400767 } else if (phba->work_hs & HS_CRIT_TEMP) {
768 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
769 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
770 temp_event_data.event_code = LPFC_CRIT_TEMP;
771 temp_event_data.data = (uint32_t)temperature;
772
773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
774 "0459 Adapter maximum temperature exceeded "
775 "(%ld), taking this port offline "
776 "Data: x%x x%x x%x\n",
777 temperature, phba->work_hs,
778 phba->work_status[0], phba->work_status[1]);
779
780 shost = lpfc_shost_from_vport(phba->pport);
781 fc_host_post_vendor_event(shost, fc_get_event_number(),
782 sizeof(temp_event_data),
783 (char *) &temp_event_data,
784 SCSI_NL_VID_TYPE_PCI
785 | PCI_VENDOR_ID_EMULEX);
786
James Smart7af67052007-10-27 13:38:11 -0400787 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400788 phba->over_temp_state = HBA_OVER_TEMP;
789 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500790 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400791
dea31012005-04-17 16:05:31 -0500792 } else {
793 /* The if clause above forces this code path when the status
794 * failure is a value other than FFER6. Do not call the offline
795 * twice. This is the adapter hardware error path.
796 */
797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400798 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500799 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400800 phba->work_hs,
dea31012005-04-17 16:05:31 -0500801 phba->work_status[0], phba->work_status[1]);
802
James Smartd2873e42006-08-18 17:46:43 -0400803 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500804 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500805 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400806 sizeof(event_data), (char *) &event_data,
807 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
808
James Smart09372822008-01-11 01:52:54 -0500809 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500810 }
811}
812
813/************************************************************************/
814/* */
815/* lpfc_handle_latt */
816/* This routine will handle processing a Host Attention */
817/* Link Status event. This will be initialized */
818/* as a SLI layer callback routine. */
819/* */
820/************************************************************************/
821void
James Smart2e0fef82007-06-17 19:56:36 -0500822lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500823{
James Smart2e0fef82007-06-17 19:56:36 -0500824 struct lpfc_vport *vport = phba->pport;
825 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500826 LPFC_MBOXQ_t *pmb;
827 volatile uint32_t control;
828 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500829 int rc = 0;
dea31012005-04-17 16:05:31 -0500830
831 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500832 if (!pmb) {
833 rc = 1;
dea31012005-04-17 16:05:31 -0500834 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500835 }
dea31012005-04-17 16:05:31 -0500836
837 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500838 if (!mp) {
839 rc = 2;
dea31012005-04-17 16:05:31 -0500840 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500841 }
dea31012005-04-17 16:05:31 -0500842
843 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500844 if (!mp->virt) {
845 rc = 3;
dea31012005-04-17 16:05:31 -0500846 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500847 }
dea31012005-04-17 16:05:31 -0500848
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500849 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400850 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500851
852 psli->slistat.link_event++;
853 lpfc_read_la(phba, pmb, mp);
854 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500855 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -0400856 /* Block ELS IOCBs until we have processed this mbox command */
857 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -0400858 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500859 if (rc == MBX_NOT_FINISHED) {
860 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500861 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500862 }
dea31012005-04-17 16:05:31 -0500863
864 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500865 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500866 writel(HA_LATT, phba->HAregaddr);
867 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500868 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500869
870 return;
871
James Smart14691152006-12-02 13:34:28 -0500872lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -0400873 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -0500874 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500875lpfc_handle_latt_free_mp:
876 kfree(mp);
877lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400878 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500879lpfc_handle_latt_err_exit:
880 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500882 psli->sli_flag |= LPFC_PROCESS_LA;
883 control = readl(phba->HCregaddr);
884 control |= HC_LAINT_ENA;
885 writel(control, phba->HCregaddr);
886 readl(phba->HCregaddr); /* flush */
887
888 /* Clear Link Attention in HA REG */
889 writel(HA_LATT, phba->HAregaddr);
890 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500891 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500892 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500893 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500894
James Smart09372822008-01-11 01:52:54 -0500895 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
896 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500897
898 return;
899}
900
901/************************************************************************/
902/* */
903/* lpfc_parse_vpd */
904/* This routine will parse the VPD data */
905/* */
906/************************************************************************/
907static int
James Smart2e0fef82007-06-17 19:56:36 -0500908lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500909{
910 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500911 int Length;
dea31012005-04-17 16:05:31 -0500912 int i, j;
913 int finished = 0;
914 int index = 0;
915
916 if (!vpd)
917 return 0;
918
919 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500920 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400921 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500922 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
923 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500924 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500925 switch (vpd[index]) {
926 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500927 case 0x91:
dea31012005-04-17 16:05:31 -0500928 index += 1;
929 lenlo = vpd[index];
930 index += 1;
931 lenhi = vpd[index];
932 index += 1;
933 i = ((((unsigned short)lenhi) << 8) + lenlo);
934 index += i;
935 break;
936 case 0x90:
937 index += 1;
938 lenlo = vpd[index];
939 index += 1;
940 lenhi = vpd[index];
941 index += 1;
942 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500943 if (Length > len - index)
944 Length = len - index;
dea31012005-04-17 16:05:31 -0500945 while (Length > 0) {
946 /* Look for Serial Number */
947 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
948 index += 2;
949 i = vpd[index];
950 index += 1;
951 j = 0;
952 Length -= (3+i);
953 while(i--) {
954 phba->SerialNumber[j++] = vpd[index++];
955 if (j == 31)
956 break;
957 }
958 phba->SerialNumber[j] = 0;
959 continue;
960 }
961 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
962 phba->vpd_flag |= VPD_MODEL_DESC;
963 index += 2;
964 i = vpd[index];
965 index += 1;
966 j = 0;
967 Length -= (3+i);
968 while(i--) {
969 phba->ModelDesc[j++] = vpd[index++];
970 if (j == 255)
971 break;
972 }
973 phba->ModelDesc[j] = 0;
974 continue;
975 }
976 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
977 phba->vpd_flag |= VPD_MODEL_NAME;
978 index += 2;
979 i = vpd[index];
980 index += 1;
981 j = 0;
982 Length -= (3+i);
983 while(i--) {
984 phba->ModelName[j++] = vpd[index++];
985 if (j == 79)
986 break;
987 }
988 phba->ModelName[j] = 0;
989 continue;
990 }
991 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
992 phba->vpd_flag |= VPD_PROGRAM_TYPE;
993 index += 2;
994 i = vpd[index];
995 index += 1;
996 j = 0;
997 Length -= (3+i);
998 while(i--) {
999 phba->ProgramType[j++] = vpd[index++];
1000 if (j == 255)
1001 break;
1002 }
1003 phba->ProgramType[j] = 0;
1004 continue;
1005 }
1006 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1007 phba->vpd_flag |= VPD_PORT;
1008 index += 2;
1009 i = vpd[index];
1010 index += 1;
1011 j = 0;
1012 Length -= (3+i);
1013 while(i--) {
1014 phba->Port[j++] = vpd[index++];
1015 if (j == 19)
1016 break;
1017 }
1018 phba->Port[j] = 0;
1019 continue;
1020 }
1021 else {
1022 index += 2;
1023 i = vpd[index];
1024 index += 1;
1025 index += i;
1026 Length -= (3 + i);
1027 }
1028 }
1029 finished = 0;
1030 break;
1031 case 0x78:
1032 finished = 1;
1033 break;
1034 default:
1035 index ++;
1036 break;
1037 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001038 }
dea31012005-04-17 16:05:31 -05001039
1040 return(1);
1041}
1042
1043static void
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001045{
1046 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001047 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001048 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001049 struct {
1050 char * name;
1051 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001052 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001053 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001054
1055 if (mdp && mdp[0] != '\0'
1056 && descp && descp[0] != '\0')
1057 return;
1058
1059 if (phba->lmt & LMT_10Gb)
1060 max_speed = 10;
1061 else if (phba->lmt & LMT_8Gb)
1062 max_speed = 8;
1063 else if (phba->lmt & LMT_4Gb)
1064 max_speed = 4;
1065 else if (phba->lmt & LMT_2Gb)
1066 max_speed = 2;
1067 else
1068 max_speed = 1;
dea31012005-04-17 16:05:31 -05001069
1070 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001071
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001072 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001073 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001074 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001075 break;
dea31012005-04-17 16:05:31 -05001076 case PCI_DEVICE_ID_SUPERFLY:
1077 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001078 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001079 else
James Smart18a3b592006-12-02 13:35:08 -05001080 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001081 break;
1082 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001083 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001084 break;
1085 case PCI_DEVICE_ID_CENTAUR:
1086 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001087 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001088 else
James Smart18a3b592006-12-02 13:35:08 -05001089 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001090 break;
1091 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001092 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001093 break;
1094 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001095 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001096 break;
1097 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001098 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001099 break;
1100 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001101 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001102 break;
1103 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001104 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001105 break;
1106 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001107 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001108 break;
1109 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001110 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001111 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001112 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001113 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001114 break;
1115 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001116 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001117 break;
1118 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001119 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001120 break;
1121 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001122 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001123 break;
1124 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001125 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001126 break;
dea31012005-04-17 16:05:31 -05001127 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001128 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001129 break;
1130 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001131 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001132 break;
1133 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001134 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001135 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001136 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001137 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001138 break;
1139 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001140 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001141 break;
dea31012005-04-17 16:05:31 -05001142 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001143 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001144 break;
1145 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001146 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001147 break;
1148 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001149 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001150 break;
1151 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001152 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001153 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001154 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001155 m = (typeof(m)){"LP11000-S", max_speed,
1156 "PCI-X2"};
1157 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001158 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001159 m = (typeof(m)){"LPe11000-S", max_speed,
1160 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001161 break;
James Smartb87eab32007-04-25 09:53:28 -04001162 case PCI_DEVICE_ID_SAT:
1163 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1164 break;
1165 case PCI_DEVICE_ID_SAT_MID:
1166 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1167 break;
1168 case PCI_DEVICE_ID_SAT_SMB:
1169 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1170 break;
1171 case PCI_DEVICE_ID_SAT_DCSP:
1172 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1173 break;
1174 case PCI_DEVICE_ID_SAT_SCSP:
1175 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1176 break;
1177 case PCI_DEVICE_ID_SAT_S:
1178 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1179 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001180 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001181 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001182 break;
dea31012005-04-17 16:05:31 -05001183 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001184
1185 if (mdp && mdp[0] == '\0')
1186 snprintf(mdp, 79,"%s", m.name);
1187 if (descp && descp[0] == '\0')
1188 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001189 "Emulex %s %dGb %s Fibre Channel Adapter",
1190 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001191}
1192
1193/**************************************************/
1194/* lpfc_post_buffer */
1195/* */
1196/* This routine will post count buffers to the */
1197/* ring with the QUE_RING_BUF_CN command. This */
1198/* allows 3 buffers / command to be posted. */
1199/* Returns the number of buffers NOT posted. */
1200/**************************************************/
1201int
James Smart495a7142008-06-14 22:52:59 -04001202lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001203{
1204 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001205 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001206 struct lpfc_dmabuf *mp1, *mp2;
1207
1208 cnt += pring->missbufcnt;
1209
1210 /* While there are buffers to post */
1211 while (cnt > 0) {
1212 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001213 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001214 if (iocb == NULL) {
1215 pring->missbufcnt = cnt;
1216 return cnt;
1217 }
dea31012005-04-17 16:05:31 -05001218 icmd = &iocb->iocb;
1219
1220 /* 2 buffers can be posted per command */
1221 /* Allocate buffer to post */
1222 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1223 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001224 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1225 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001226 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001227 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001228 pring->missbufcnt = cnt;
1229 return cnt;
1230 }
1231
1232 INIT_LIST_HEAD(&mp1->list);
1233 /* Allocate buffer to post */
1234 if (cnt > 1) {
1235 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1236 if (mp2)
1237 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1238 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001239 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001240 kfree(mp2);
dea31012005-04-17 16:05:31 -05001241 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1242 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001243 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001244 pring->missbufcnt = cnt;
1245 return cnt;
1246 }
1247
1248 INIT_LIST_HEAD(&mp2->list);
1249 } else {
1250 mp2 = NULL;
1251 }
1252
1253 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1254 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1255 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1256 icmd->ulpBdeCount = 1;
1257 cnt--;
1258 if (mp2) {
1259 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1260 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1261 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1262 cnt--;
1263 icmd->ulpBdeCount = 2;
1264 }
1265
1266 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1267 icmd->ulpLe = 1;
1268
dea31012005-04-17 16:05:31 -05001269 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1270 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1271 kfree(mp1);
1272 cnt++;
1273 if (mp2) {
1274 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1275 kfree(mp2);
1276 cnt++;
1277 }
James Bottomley604a3e32005-10-29 10:28:33 -05001278 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001279 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001280 return cnt;
1281 }
dea31012005-04-17 16:05:31 -05001282 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001283 if (mp2)
dea31012005-04-17 16:05:31 -05001284 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001285 }
1286 pring->missbufcnt = 0;
1287 return 0;
1288}
1289
1290/************************************************************************/
1291/* */
1292/* lpfc_post_rcv_buf */
1293/* This routine post initial rcv buffers to the configured rings */
1294/* */
1295/************************************************************************/
1296static int
James Smart2e0fef82007-06-17 19:56:36 -05001297lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001298{
1299 struct lpfc_sli *psli = &phba->sli;
1300
1301 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001302 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001303 /* Ring 2 - FCP no buffers needed */
1304
1305 return 0;
1306}
1307
1308#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1309
1310/************************************************************************/
1311/* */
1312/* lpfc_sha_init */
1313/* */
1314/************************************************************************/
1315static void
1316lpfc_sha_init(uint32_t * HashResultPointer)
1317{
1318 HashResultPointer[0] = 0x67452301;
1319 HashResultPointer[1] = 0xEFCDAB89;
1320 HashResultPointer[2] = 0x98BADCFE;
1321 HashResultPointer[3] = 0x10325476;
1322 HashResultPointer[4] = 0xC3D2E1F0;
1323}
1324
1325/************************************************************************/
1326/* */
1327/* lpfc_sha_iterate */
1328/* */
1329/************************************************************************/
1330static void
1331lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1332{
1333 int t;
1334 uint32_t TEMP;
1335 uint32_t A, B, C, D, E;
1336 t = 16;
1337 do {
1338 HashWorkingPointer[t] =
1339 S(1,
1340 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1341 8] ^
1342 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1343 } while (++t <= 79);
1344 t = 0;
1345 A = HashResultPointer[0];
1346 B = HashResultPointer[1];
1347 C = HashResultPointer[2];
1348 D = HashResultPointer[3];
1349 E = HashResultPointer[4];
1350
1351 do {
1352 if (t < 20) {
1353 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1354 } else if (t < 40) {
1355 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1356 } else if (t < 60) {
1357 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1358 } else {
1359 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1360 }
1361 TEMP += S(5, A) + E + HashWorkingPointer[t];
1362 E = D;
1363 D = C;
1364 C = S(30, B);
1365 B = A;
1366 A = TEMP;
1367 } while (++t <= 79);
1368
1369 HashResultPointer[0] += A;
1370 HashResultPointer[1] += B;
1371 HashResultPointer[2] += C;
1372 HashResultPointer[3] += D;
1373 HashResultPointer[4] += E;
1374
1375}
1376
1377/************************************************************************/
1378/* */
1379/* lpfc_challenge_key */
1380/* */
1381/************************************************************************/
1382static void
1383lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1384{
1385 *HashWorking = (*RandomChallenge ^ *HashWorking);
1386}
1387
1388/************************************************************************/
1389/* */
1390/* lpfc_hba_init */
1391/* */
1392/************************************************************************/
1393void
1394lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1395{
1396 int t;
1397 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001398 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001399
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001400 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001401 if (!HashWorking)
1402 return;
1403
dea31012005-04-17 16:05:31 -05001404 HashWorking[0] = HashWorking[78] = *pwwnn++;
1405 HashWorking[1] = HashWorking[79] = *pwwnn;
1406
1407 for (t = 0; t < 7; t++)
1408 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1409
1410 lpfc_sha_init(hbainit);
1411 lpfc_sha_iterate(hbainit, HashWorking);
1412 kfree(HashWorking);
1413}
1414
James Smart87af33f2007-10-27 13:37:43 -04001415void
James Smart2e0fef82007-06-17 19:56:36 -05001416lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001417{
James Smart87af33f2007-10-27 13:37:43 -04001418 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001419 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001420 int i = 0;
dea31012005-04-17 16:05:31 -05001421
James Smart87af33f2007-10-27 13:37:43 -04001422 if (phba->link_state > LPFC_LINK_DOWN)
1423 lpfc_port_link_failure(vport);
1424
1425 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001426 if (!NLP_CHK_NODE_ACT(ndlp)) {
1427 ndlp = lpfc_enable_node(vport, ndlp,
1428 NLP_STE_UNUSED_NODE);
1429 if (!ndlp)
1430 continue;
1431 spin_lock_irq(&phba->ndlp_lock);
1432 NLP_SET_FREE_REQ(ndlp);
1433 spin_unlock_irq(&phba->ndlp_lock);
1434 /* Trigger the release of the ndlp memory */
1435 lpfc_nlp_put(ndlp);
1436 continue;
1437 }
1438 spin_lock_irq(&phba->ndlp_lock);
1439 if (NLP_CHK_FREE_REQ(ndlp)) {
1440 /* The ndlp should not be in memory free mode already */
1441 spin_unlock_irq(&phba->ndlp_lock);
1442 continue;
1443 } else
1444 /* Indicate request for freeing ndlp memory */
1445 NLP_SET_FREE_REQ(ndlp);
1446 spin_unlock_irq(&phba->ndlp_lock);
1447
James Smart58da1ff2008-04-07 10:15:56 -04001448 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1449 ndlp->nlp_DID == Fabric_DID) {
1450 /* Just free up ndlp with Fabric_DID for vports */
1451 lpfc_nlp_put(ndlp);
1452 continue;
1453 }
1454
James Smart87af33f2007-10-27 13:37:43 -04001455 if (ndlp->nlp_type & NLP_FABRIC)
1456 lpfc_disc_state_machine(vport, ndlp, NULL,
1457 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001458
James Smart87af33f2007-10-27 13:37:43 -04001459 lpfc_disc_state_machine(vport, ndlp, NULL,
1460 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001461
1462 /* nlp_type zero is not defined, nlp_flag zero also not defined,
1463 * nlp_state is unused, this happens when
1464 * an initiator has logged
1465 * into us so cleanup this ndlp.
1466 */
1467 if ((ndlp->nlp_type == 0) && (ndlp->nlp_flag == 0) &&
1468 (ndlp->nlp_state == 0))
1469 lpfc_nlp_put(ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001470 }
1471
James Smarta8adb832007-10-27 13:37:53 -04001472 /* At this point, ALL ndlp's should be gone
1473 * because of the previous NLP_EVT_DEVICE_RM.
1474 * Lets wait for this to happen, if needed.
1475 */
James Smart87af33f2007-10-27 13:37:43 -04001476 while (!list_empty(&vport->fc_nodes)) {
1477
James Smarta8adb832007-10-27 13:37:53 -04001478 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001479 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001480 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001481 list_for_each_entry_safe(ndlp, next_ndlp,
1482 &vport->fc_nodes, nlp_listp) {
1483 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1484 LOG_NODE,
1485 "0282: did:x%x ndlp:x%p "
1486 "usgmap:x%x refcnt:%d\n",
1487 ndlp->nlp_DID, (void *)ndlp,
1488 ndlp->nlp_usg_map,
1489 atomic_read(
1490 &ndlp->kref.refcount));
1491 }
James Smarta8adb832007-10-27 13:37:53 -04001492 break;
James Smart87af33f2007-10-27 13:37:43 -04001493 }
James Smarta8adb832007-10-27 13:37:53 -04001494
1495 /* Wait for any activity on ndlps to settle */
1496 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001497 }
dea31012005-04-17 16:05:31 -05001498 return;
1499}
1500
James Smart92d7f7b2007-06-17 19:56:38 -05001501void
1502lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001503{
James Smart92d7f7b2007-06-17 19:56:38 -05001504 del_timer_sync(&vport->els_tmofunc);
1505 del_timer_sync(&vport->fc_fdmitmo);
1506 lpfc_can_disctmo(vport);
1507 return;
dea31012005-04-17 16:05:31 -05001508}
1509
James Smart2e0fef82007-06-17 19:56:36 -05001510static void
James Smart92d7f7b2007-06-17 19:56:38 -05001511lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001512{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001513 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001514 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001515 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001516 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001517 phba->hb_outstanding = 0;
1518 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001519 return;
dea31012005-04-17 16:05:31 -05001520}
1521
Adrian Bunka6ababd2007-11-05 18:07:33 +01001522static void
1523lpfc_block_mgmt_io(struct lpfc_hba * phba)
1524{
1525 unsigned long iflag;
1526
1527 spin_lock_irqsave(&phba->hbalock, iflag);
1528 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1529 spin_unlock_irqrestore(&phba->hbalock, iflag);
1530}
1531
dea31012005-04-17 16:05:31 -05001532int
James Smart2e0fef82007-06-17 19:56:36 -05001533lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001534{
James Smart2e0fef82007-06-17 19:56:36 -05001535 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001536 struct lpfc_vport **vports;
1537 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001538
dea31012005-04-17 16:05:31 -05001539 if (!phba)
1540 return 0;
1541
James Smart2e0fef82007-06-17 19:56:36 -05001542 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001543 return 0;
1544
James Smarted957682007-06-17 19:56:37 -05001545 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001546 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001547
James Smart46fa3112007-04-25 09:51:45 -04001548 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001549
James Smart46fa3112007-04-25 09:51:45 -04001550 if (!lpfc_sli_queue_setup(phba)) {
1551 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001552 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001553 }
1554
1555 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1556 lpfc_unblock_mgmt_io(phba);
1557 return 1;
1558 }
dea31012005-04-17 16:05:31 -05001559
James Smart549e55c2007-08-02 11:09:51 -04001560 vports = lpfc_create_vport_work_array(phba);
1561 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001562 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001563 struct Scsi_Host *shost;
1564 shost = lpfc_shost_from_vport(vports[i]);
1565 spin_lock_irq(shost->host_lock);
1566 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1567 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1568 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1569 spin_unlock_irq(shost->host_lock);
1570 }
James Smart09372822008-01-11 01:52:54 -05001571 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001572
James Smart46fa3112007-04-25 09:51:45 -04001573 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001574 return 0;
1575}
1576
James Smart46fa3112007-04-25 09:51:45 -04001577void
James Smart46fa3112007-04-25 09:51:45 -04001578lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1579{
1580 unsigned long iflag;
1581
James Smart2e0fef82007-06-17 19:56:36 -05001582 spin_lock_irqsave(&phba->hbalock, iflag);
1583 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1584 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001585}
1586
1587void
1588lpfc_offline_prep(struct lpfc_hba * phba)
1589{
James Smart2e0fef82007-06-17 19:56:36 -05001590 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001591 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001592 struct lpfc_vport **vports;
1593 int i;
dea31012005-04-17 16:05:31 -05001594
James Smart2e0fef82007-06-17 19:56:36 -05001595 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001596 return;
dea31012005-04-17 16:05:31 -05001597
James Smart46fa3112007-04-25 09:51:45 -04001598 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001599
1600 lpfc_linkdown(phba);
1601
James Smart87af33f2007-10-27 13:37:43 -04001602 /* Issue an unreg_login to all nodes on all vports */
1603 vports = lpfc_create_vport_work_array(phba);
1604 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001605 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001606 struct Scsi_Host *shost;
1607
James Smarta8adb832007-10-27 13:37:53 -04001608 if (vports[i]->load_flag & FC_UNLOADING)
1609 continue;
James Smart87af33f2007-10-27 13:37:43 -04001610 shost = lpfc_shost_from_vport(vports[i]);
1611 list_for_each_entry_safe(ndlp, next_ndlp,
1612 &vports[i]->fc_nodes,
1613 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001614 if (!NLP_CHK_NODE_ACT(ndlp))
1615 continue;
James Smart87af33f2007-10-27 13:37:43 -04001616 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1617 continue;
1618 if (ndlp->nlp_type & NLP_FABRIC) {
1619 lpfc_disc_state_machine(vports[i], ndlp,
1620 NULL, NLP_EVT_DEVICE_RECOVERY);
1621 lpfc_disc_state_machine(vports[i], ndlp,
1622 NULL, NLP_EVT_DEVICE_RM);
1623 }
1624 spin_lock_irq(shost->host_lock);
1625 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1626 spin_unlock_irq(shost->host_lock);
1627 lpfc_unreg_rpi(vports[i], ndlp);
1628 }
1629 }
1630 }
James Smart09372822008-01-11 01:52:54 -05001631 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001632
James Smart46fa3112007-04-25 09:51:45 -04001633 lpfc_sli_flush_mbox_queue(phba);
1634}
1635
1636void
James Smart2e0fef82007-06-17 19:56:36 -05001637lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001638{
James Smart549e55c2007-08-02 11:09:51 -04001639 struct Scsi_Host *shost;
1640 struct lpfc_vport **vports;
1641 int i;
James Smart46fa3112007-04-25 09:51:45 -04001642
James Smart549e55c2007-08-02 11:09:51 -04001643 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001644 return;
James Smart688a8862006-07-06 15:49:56 -04001645
dea31012005-04-17 16:05:31 -05001646 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001647 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001648 vports = lpfc_create_vport_work_array(phba);
1649 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001650 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001651 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001652 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001653 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001654 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001655 /* Bring down the SLI Layer and cleanup. The HBA is offline
1656 now. */
1657 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001658 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001659 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001660 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001661 vports = lpfc_create_vport_work_array(phba);
1662 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001663 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001664 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001665 spin_lock_irq(shost->host_lock);
1666 vports[i]->work_port_events = 0;
1667 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1668 spin_unlock_irq(shost->host_lock);
1669 }
James Smart09372822008-01-11 01:52:54 -05001670 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001671}
1672
1673/******************************************************************************
1674* Function name: lpfc_scsi_free
1675*
1676* Description: Called from lpfc_pci_remove_one free internal driver resources
1677*
1678******************************************************************************/
1679static int
James Smart2e0fef82007-06-17 19:56:36 -05001680lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001681{
1682 struct lpfc_scsi_buf *sb, *sb_next;
1683 struct lpfc_iocbq *io, *io_next;
1684
James Smart2e0fef82007-06-17 19:56:36 -05001685 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001686 /* Release all the lpfc_scsi_bufs maintained by this host. */
1687 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1688 list_del(&sb->list);
1689 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001690 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001691 kfree(sb);
1692 phba->total_scsi_bufs--;
1693 }
1694
1695 /* Release all the lpfc_iocbq entries maintained by this host. */
1696 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1697 list_del(&io->list);
1698 kfree(io);
1699 phba->total_iocbq_bufs--;
1700 }
1701
James Smart2e0fef82007-06-17 19:56:36 -05001702 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001703
1704 return 0;
1705}
1706
James Smart2e0fef82007-06-17 19:56:36 -05001707struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001708lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001709{
James Smart2e0fef82007-06-17 19:56:36 -05001710 struct lpfc_vport *vport;
1711 struct Scsi_Host *shost;
1712 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001713
James Smart3de2a652007-08-02 11:09:59 -04001714 if (dev != &phba->pcidev->dev)
1715 shost = scsi_host_alloc(&lpfc_vport_template,
1716 sizeof(struct lpfc_vport));
1717 else
1718 shost = scsi_host_alloc(&lpfc_template,
1719 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001720 if (!shost)
1721 goto out;
James Smart47a86172007-04-25 09:53:22 -04001722
James Smart2e0fef82007-06-17 19:56:36 -05001723 vport = (struct lpfc_vport *) shost->hostdata;
1724 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05001725 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001726 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05001727 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04001728
James Smart3de2a652007-08-02 11:09:59 -04001729 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001730 shost->unique_id = instance;
1731 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001732 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001733 shost->this_id = -1;
1734 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001735 /*
James Smart2e0fef82007-06-17 19:56:36 -05001736 * Set initial can_queue value since 0 is no longer supported and
1737 * scsi_add_host will fail. This will be adjusted later based on the
1738 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001739 */
James Smart2e0fef82007-06-17 19:56:36 -05001740 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001741 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001742 shost->transportt = lpfc_vport_transport_template;
1743 vport->port_type = LPFC_NPIV_PORT;
1744 } else {
1745 shost->transportt = lpfc_transport_template;
1746 vport->port_type = LPFC_PHYSICAL_PORT;
1747 }
James Smart47a86172007-04-25 09:53:22 -04001748
James Smart2e0fef82007-06-17 19:56:36 -05001749 /* Initialize all internally managed lists. */
1750 INIT_LIST_HEAD(&vport->fc_nodes);
1751 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001752
James Smart2e0fef82007-06-17 19:56:36 -05001753 init_timer(&vport->fc_disctmo);
1754 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001755 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001756
James Smart2e0fef82007-06-17 19:56:36 -05001757 init_timer(&vport->fc_fdmitmo);
1758 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001759 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001760
James Smart2e0fef82007-06-17 19:56:36 -05001761 init_timer(&vport->els_tmofunc);
1762 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001763 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001764
James Smart3de2a652007-08-02 11:09:59 -04001765 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001766 if (error)
1767 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001768
James Smart549e55c2007-08-02 11:09:51 -04001769 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001770 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001771 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001772 return vport;
James Smart47a86172007-04-25 09:53:22 -04001773
James Smart2e0fef82007-06-17 19:56:36 -05001774out_put_shost:
1775 scsi_host_put(shost);
1776out:
1777 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001778}
1779
James Smart2e0fef82007-06-17 19:56:36 -05001780void
1781destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001782{
James Smart92d7f7b2007-06-17 19:56:38 -05001783 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1784 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001785
James Smart92d7f7b2007-06-17 19:56:38 -05001786 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001787
James Smart858c9f62007-06-17 19:56:39 -05001788 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001789 fc_remove_host(shost);
1790 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001791
James Smart92d7f7b2007-06-17 19:56:38 -05001792 spin_lock_irq(&phba->hbalock);
1793 list_del_init(&vport->listentry);
1794 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001795
James Smart92d7f7b2007-06-17 19:56:38 -05001796 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001797 return;
James Smart47a86172007-04-25 09:53:22 -04001798}
1799
James Smart92d7f7b2007-06-17 19:56:38 -05001800int
1801lpfc_get_instance(void)
1802{
1803 int instance = 0;
1804
1805 /* Assign an unused number */
1806 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1807 return -1;
1808 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1809 return -1;
1810 return instance;
1811}
1812
James Smart858c9f62007-06-17 19:56:39 -05001813/*
1814 * Note: there is no scan_start function as adapter initialization
1815 * will have asynchronously kicked off the link initialization.
1816 */
James Smart47a86172007-04-25 09:53:22 -04001817
1818int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1819{
James Smart2e0fef82007-06-17 19:56:36 -05001820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1821 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001822 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001823
James Smart858c9f62007-06-17 19:56:39 -05001824 spin_lock_irq(shost->host_lock);
1825
James Smart51ef4c22007-08-02 11:10:31 -04001826 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05001827 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001828 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001829 }
James Smart2e0fef82007-06-17 19:56:36 -05001830 if (time >= 30 * HZ) {
1831 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001832 "0461 Scanning longer than 30 "
1833 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001834 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001835 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001836 }
1837 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1838 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001839 "0465 Link down longer than 15 "
1840 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001841 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001842 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001843 }
1844
James Smart2e0fef82007-06-17 19:56:36 -05001845 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001846 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001847 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001848 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001849 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001850 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001851 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001852 goto finished;
1853
1854 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001855
1856finished:
James Smart858c9f62007-06-17 19:56:39 -05001857 spin_unlock_irq(shost->host_lock);
1858 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001859}
1860
1861void lpfc_host_attrib_init(struct Scsi_Host *shost)
1862{
1863 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1864 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001865 /*
James Smart2e0fef82007-06-17 19:56:36 -05001866 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001867 */
1868
James Smart2e0fef82007-06-17 19:56:36 -05001869 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1870 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001871 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1872
1873 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001874 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001875 fc_host_supported_fc4s(shost)[2] = 1;
1876 fc_host_supported_fc4s(shost)[7] = 1;
1877
James Smart92d7f7b2007-06-17 19:56:38 -05001878 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1879 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001880
1881 fc_host_supported_speeds(shost) = 0;
1882 if (phba->lmt & LMT_10Gb)
1883 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04001884 if (phba->lmt & LMT_8Gb)
1885 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04001886 if (phba->lmt & LMT_4Gb)
1887 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1888 if (phba->lmt & LMT_2Gb)
1889 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1890 if (phba->lmt & LMT_1Gb)
1891 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1892
1893 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001894 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1895 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001896
1897 /* This value is also unchanging */
1898 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001899 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001900 fc_host_active_fc4s(shost)[2] = 1;
1901 fc_host_active_fc4s(shost)[7] = 1;
1902
James Smart92d7f7b2007-06-17 19:56:38 -05001903 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001904 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001905 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001906 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001907}
dea31012005-04-17 16:05:31 -05001908
James Smartdb2378e2008-02-08 18:49:51 -05001909static int
1910lpfc_enable_msix(struct lpfc_hba *phba)
1911{
1912 int error;
1913
1914 phba->msix_entries[0].entry = 0;
1915 phba->msix_entries[0].vector = 0;
1916
1917 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
1918 ARRAY_SIZE(phba->msix_entries));
1919 if (error) {
1920 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1921 "0420 Enable MSI-X failed (%d), continuing "
1922 "with MSI\n", error);
1923 pci_disable_msix(phba->pcidev);
1924 return error;
1925 }
1926
1927 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
1928 LPFC_DRIVER_NAME, phba);
1929 if (error) {
1930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1931 "0421 MSI-X request_irq failed (%d), "
1932 "continuing with MSI\n", error);
1933 pci_disable_msix(phba->pcidev);
1934 }
1935 return error;
1936}
1937
1938static void
1939lpfc_disable_msix(struct lpfc_hba *phba)
1940{
1941 free_irq(phba->msix_entries[0].vector, phba);
1942 pci_disable_msix(phba->pcidev);
1943}
1944
dea31012005-04-17 16:05:31 -05001945static int __devinit
1946lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1947{
James Smart2e0fef82007-06-17 19:56:36 -05001948 struct lpfc_vport *vport = NULL;
1949 struct lpfc_hba *phba;
1950 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001951 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001952 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04001953 void *ptr;
dea31012005-04-17 16:05:31 -05001954 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04001955 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04001956 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05001957 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001958 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05001959
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01001960 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05001961 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001962 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05001963 goto out_disable_device;
1964
James Smart2e0fef82007-06-17 19:56:36 -05001965 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1966 if (!phba)
dea31012005-04-17 16:05:31 -05001967 goto out_release_regions;
1968
James Smart2e0fef82007-06-17 19:56:36 -05001969 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001970
James Smarte47c9092008-02-08 18:49:26 -05001971 /* Initialize ndlp management spinlock */
1972 spin_lock_init(&phba->ndlp_lock);
1973
dea31012005-04-17 16:05:31 -05001974 phba->pcidev = pdev;
1975
1976 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001977 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001978 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001979
James Smart2e0fef82007-06-17 19:56:36 -05001980 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05001981 /*
1982 * Get all the module params for configuring this host and then
1983 * establish the host.
1984 */
1985 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001986 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05001987
1988 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05001989 init_timer(&phba->hb_tmofunc);
1990 phba->hb_tmofunc.function = lpfc_hb_timeout;
1991 phba->hb_tmofunc.data = (unsigned long)phba;
1992
dea31012005-04-17 16:05:31 -05001993 psli = &phba->sli;
1994 init_timer(&psli->mbox_tmo);
1995 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001996 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001997 init_timer(&phba->fcp_poll_timer);
1998 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001999 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002000 init_timer(&phba->fabric_block_timer);
2001 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2002 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002003
dea31012005-04-17 16:05:31 -05002004 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002005 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002006
2007 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2008 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2009 goto out_idr_remove;
2010
2011 /*
2012 * Get the bus address of Bar0 and Bar2 and the number of bytes
2013 * required by each mapping.
2014 */
2015 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2016 bar0map_len = pci_resource_len(phba->pcidev, 0);
2017
2018 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2019 bar2map_len = pci_resource_len(phba->pcidev, 2);
2020
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002021 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002022 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002023 if (!phba->slim_memmap_p) {
2024 error = -ENODEV;
2025 dev_printk(KERN_ERR, &pdev->dev,
2026 "ioremap failed for SLIM memory.\n");
2027 goto out_idr_remove;
2028 }
2029
2030 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002031 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002032 if (!phba->ctrl_regs_memmap_p) {
2033 error = -ENODEV;
2034 dev_printk(KERN_ERR, &pdev->dev,
2035 "ioremap failed for HBA control registers.\n");
2036 goto out_iounmap_slim;
2037 }
dea31012005-04-17 16:05:31 -05002038
2039 /* Allocate memory for SLI-2 structures */
2040 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
2041 &phba->slim2p_mapping, GFP_KERNEL);
2042 if (!phba->slim2p)
2043 goto out_iounmap;
2044
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04002045 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05002046
James Smarted957682007-06-17 19:56:37 -05002047 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2048 lpfc_sli_hbq_size(),
2049 &phba->hbqslimp.phys,
2050 GFP_KERNEL);
2051 if (!phba->hbqslimp.virt)
2052 goto out_free_slim;
2053
James Smart51ef4c22007-08-02 11:10:31 -04002054 hbq_count = lpfc_sli_hbq_count();
2055 ptr = phba->hbqslimp.virt;
2056 for (i = 0; i < hbq_count; ++i) {
2057 phba->hbqs[i].hbq_virt = ptr;
2058 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2059 ptr += (lpfc_hbq_defs[i]->entry_count *
2060 sizeof(struct lpfc_hbq_entry));
2061 }
2062 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2063 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2064
James Smarted957682007-06-17 19:56:37 -05002065 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2066
James Smart3163f722008-02-08 18:50:25 -05002067 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2068
dea31012005-04-17 16:05:31 -05002069 /* Initialize the SLI Layer to run with lpfc HBAs. */
2070 lpfc_sli_setup(phba);
2071 lpfc_sli_queue_setup(phba);
2072
James Smart98c9ea52007-10-27 13:37:33 -04002073 retval = lpfc_mem_alloc(phba);
2074 if (retval) {
2075 error = retval;
James Smarted957682007-06-17 19:56:37 -05002076 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002077 }
dea31012005-04-17 16:05:31 -05002078
2079 /* Initialize and populate the iocb list per host. */
2080 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2081 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002082 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002083 if (iocbq_entry == NULL) {
2084 printk(KERN_ERR "%s: only allocated %d iocbs of "
2085 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002086 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002087 error = -ENOMEM;
2088 goto out_free_iocbq;
2089 }
2090
James Bottomley604a3e32005-10-29 10:28:33 -05002091 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2092 if (iotag == 0) {
2093 kfree (iocbq_entry);
2094 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2095 "Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002096 __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002097 error = -ENOMEM;
2098 goto out_free_iocbq;
2099 }
James Smart2e0fef82007-06-17 19:56:36 -05002100
2101 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002102 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2103 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002104 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002105 }
2106
2107 /* Initialize HBA structure */
2108 phba->fc_edtov = FF_DEF_EDTOV;
2109 phba->fc_ratov = FF_DEF_RATOV;
2110 phba->fc_altov = FF_DEF_ALTOV;
2111 phba->fc_arbtov = FF_DEF_ARBTOV;
2112
2113 INIT_LIST_HEAD(&phba->work_list);
2114 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2115 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2116
James Smart5e9d9b82008-06-14 22:52:53 -04002117 /* Initialize the wait queue head for the kernel thread */
2118 init_waitqueue_head(&phba->work_waitq);
2119
dea31012005-04-17 16:05:31 -05002120 /* Startup the kernel thread for this host adapter. */
2121 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2122 "lpfc_worker_%d", phba->brd_no);
2123 if (IS_ERR(phba->worker_thread)) {
2124 error = PTR_ERR(phba->worker_thread);
2125 goto out_free_iocbq;
2126 }
2127
dea31012005-04-17 16:05:31 -05002128 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002129 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002130 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2131
James Smart92d7f7b2007-06-17 19:56:38 -05002132 /* Initialize list of fabric iocbs */
2133 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2134
James Smart0ff10d42008-01-11 01:52:36 -05002135 /* Initialize list to save ELS buffers */
2136 INIT_LIST_HEAD(&phba->elsbuf);
2137
James Smart3de2a652007-08-02 11:09:59 -04002138 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002139 if (!vport)
2140 goto out_kthread_stop;
2141
2142 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002143 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002144 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002145
James Smart92d7f7b2007-06-17 19:56:38 -05002146 pci_set_drvdata(pdev, shost);
James Smartdb2378e2008-02-08 18:49:51 -05002147 phba->intr_type = NONE;
dea31012005-04-17 16:05:31 -05002148
James Smartdb2378e2008-02-08 18:49:51 -05002149 if (phba->cfg_use_msi == 2) {
2150 error = lpfc_enable_msix(phba);
2151 if (!error)
2152 phba->intr_type = MSIX;
2153 }
2154
2155 /* Fallback to MSI if MSI-X initialization failed */
2156 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
James Smart98c9ea52007-10-27 13:37:33 -04002157 retval = pci_enable_msi(phba->pcidev);
2158 if (!retval)
James Smartdb2378e2008-02-08 18:49:51 -05002159 phba->intr_type = MSI;
James Smart51ef4c22007-08-02 11:10:31 -04002160 else
James Smarte8b62012007-08-02 11:10:09 -04002161 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2162 "0452 Enable MSI failed, continuing "
2163 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002164 }
2165
James Smartdb2378e2008-02-08 18:49:51 -05002166 /* MSI-X is the only case the doesn't need to call request_irq */
2167 if (phba->intr_type != MSIX) {
2168 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2169 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2170 if (retval) {
2171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2172 "interrupt handler failed\n");
2173 error = retval;
2174 goto out_disable_msi;
2175 } else if (phba->intr_type != MSI)
2176 phba->intr_type = INTx;
dea31012005-04-17 16:05:31 -05002177 }
dea31012005-04-17 16:05:31 -05002178
James Smart2e0fef82007-06-17 19:56:36 -05002179 phba->MBslimaddr = phba->slim_memmap_p;
2180 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2181 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2182 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2183 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2184
James Smart98c9ea52007-10-27 13:37:33 -04002185 if (lpfc_alloc_sysfs_attr(vport)) {
2186 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002187 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002188 }
dea31012005-04-17 16:05:31 -05002189
James Smart98c9ea52007-10-27 13:37:33 -04002190 if (lpfc_sli_hba_setup(phba)) {
2191 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002192 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002193 }
James Smart858c9f62007-06-17 19:56:39 -05002194
2195 /*
2196 * hba setup may have changed the hba_queue_depth so we need to adjust
2197 * the value of can_queue.
2198 */
2199 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2200
2201 lpfc_host_attrib_init(shost);
2202
James Smart2e0fef82007-06-17 19:56:36 -05002203 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2204 spin_lock_irq(shost->host_lock);
2205 lpfc_poll_start_timer(phba);
2206 spin_unlock_irq(shost->host_lock);
2207 }
James Smart8f6d98d2006-08-01 07:34:00 -04002208
James Smart858c9f62007-06-17 19:56:39 -05002209 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002210
dea31012005-04-17 16:05:31 -05002211 return 0;
2212
James Smart858c9f62007-06-17 19:56:39 -05002213out_remove_device:
2214 lpfc_free_sysfs_attr(vport);
2215 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002216 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002217 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002218out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002219 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002220 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002221
2222 if (phba->intr_type == MSIX)
2223 lpfc_disable_msix(phba);
2224 else
2225 free_irq(phba->pcidev->irq, phba);
2226
James Smart92d7f7b2007-06-17 19:56:38 -05002227out_disable_msi:
James Smartdb2378e2008-02-08 18:49:51 -05002228 if (phba->intr_type == MSI)
James Smart51ef4c22007-08-02 11:10:31 -04002229 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002230 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002231out_kthread_stop:
2232 kthread_stop(phba->worker_thread);
2233out_free_iocbq:
2234 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2235 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002236 kfree(iocbq_entry);
2237 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002238 }
2239 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002240out_free_hbqslimp:
2241 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2242 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002243out_free_slim:
2244 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2245 phba->slim2p_mapping);
2246out_iounmap:
2247 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002248out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002249 iounmap(phba->slim_memmap_p);
2250out_idr_remove:
2251 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002252out_free_phba:
2253 kfree(phba);
dea31012005-04-17 16:05:31 -05002254out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002255 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002256out_disable_device:
2257 pci_disable_device(pdev);
2258out:
James Smartdefbcf12006-04-16 22:26:50 -04002259 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002260 if (shost)
2261 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002262 return error;
2263}
2264
2265static void __devexit
2266lpfc_pci_remove_one(struct pci_dev *pdev)
2267{
James Smart2e0fef82007-06-17 19:56:36 -05002268 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2269 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2270 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002271 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2272
James Smart549e55c2007-08-02 11:09:51 -04002273 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002274 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002275 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002276
James Smart858c9f62007-06-17 19:56:39 -05002277 kfree(vport->vname);
2278 lpfc_free_sysfs_attr(vport);
2279
James Smart09372822008-01-11 01:52:54 -05002280 kthread_stop(phba->worker_thread);
2281
James Smart858c9f62007-06-17 19:56:39 -05002282 fc_remove_host(shost);
2283 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002284 lpfc_cleanup(vport);
2285
James Smart2e0fef82007-06-17 19:56:36 -05002286 /*
2287 * Bring down the SLI Layer. This step disable all interrupts,
2288 * clears the rings, discards all mailbox commands, and resets
2289 * the HBA.
2290 */
2291 lpfc_sli_hba_down(phba);
2292 lpfc_sli_brdrestart(phba);
2293
James Smart92d7f7b2007-06-17 19:56:38 -05002294 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002295 spin_lock_irq(&phba->hbalock);
2296 list_del_init(&vport->listentry);
2297 spin_unlock_irq(&phba->hbalock);
2298
James Smart858c9f62007-06-17 19:56:39 -05002299 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002300
James Smartdb2378e2008-02-08 18:49:51 -05002301 if (phba->intr_type == MSIX)
2302 lpfc_disable_msix(phba);
2303 else {
2304 free_irq(phba->pcidev->irq, phba);
2305 if (phba->intr_type == MSI)
2306 pci_disable_msi(phba->pcidev);
2307 }
dea31012005-04-17 16:05:31 -05002308
2309 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002310 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002311
2312 /*
2313 * Call scsi_free before mem_free since scsi bufs are released to their
2314 * corresponding pools here.
2315 */
2316 lpfc_scsi_free(phba);
2317 lpfc_mem_free(phba);
2318
James Smarted957682007-06-17 19:56:37 -05002319 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2320 phba->hbqslimp.phys);
2321
James Smart2e0fef82007-06-17 19:56:36 -05002322 /* Free resources associated with SLI2 interface */
2323 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2324 phba->slim2p, phba->slim2p_mapping);
2325
2326 /* unmap adapter SLIM and Control Registers */
2327 iounmap(phba->ctrl_regs_memmap_p);
2328 iounmap(phba->slim_memmap_p);
2329
2330 idr_remove(&lpfc_hba_index, phba->brd_no);
2331
2332 kfree(phba);
2333
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002334 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002335 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002336}
2337
Linas Vepstas8d63f372007-02-14 14:28:36 -06002338/**
2339 * lpfc_io_error_detected - called when PCI error is detected
2340 * @pdev: Pointer to PCI device
2341 * @state: The current pci conneection state
2342 *
2343 * This function is called after a PCI bus error affecting
2344 * this device has been detected.
2345 */
2346static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2347 pci_channel_state_t state)
2348{
James Smart51ef4c22007-08-02 11:10:31 -04002349 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2350 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002351 struct lpfc_sli *psli = &phba->sli;
2352 struct lpfc_sli_ring *pring;
2353
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002354 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002355 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002356
Linas Vepstas8d63f372007-02-14 14:28:36 -06002357 pci_disable_device(pdev);
2358 /*
2359 * There may be I/Os dropped by the firmware.
2360 * Error iocb (I/O) on txcmplq and let the SCSI layer
2361 * retry it after re-establishing link.
2362 */
2363 pring = &psli->ring[psli->fcp_ring];
2364 lpfc_sli_abort_iocb_ring(phba, pring);
2365
James Smartdb2378e2008-02-08 18:49:51 -05002366 if (phba->intr_type == MSIX)
2367 lpfc_disable_msix(phba);
2368 else {
2369 free_irq(phba->pcidev->irq, phba);
2370 if (phba->intr_type == MSI)
2371 pci_disable_msi(phba->pcidev);
2372 }
James Smart51ef4c22007-08-02 11:10:31 -04002373
Linas Vepstas8d63f372007-02-14 14:28:36 -06002374 /* Request a slot reset. */
2375 return PCI_ERS_RESULT_NEED_RESET;
2376}
2377
2378/**
2379 * lpfc_io_slot_reset - called after the pci bus has been reset.
2380 * @pdev: Pointer to PCI device
2381 *
2382 * Restart the card from scratch, as if from a cold-boot.
2383 */
2384static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2385{
James Smart51ef4c22007-08-02 11:10:31 -04002386 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2387 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002388 struct lpfc_sli *psli = &phba->sli;
James Smart9b379602008-04-07 10:16:00 -04002389 int error, retval;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002390
2391 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002392 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002393 printk(KERN_ERR "lpfc: Cannot re-enable "
2394 "PCI device after reset.\n");
2395 return PCI_ERS_RESULT_DISCONNECT;
2396 }
2397
2398 pci_set_master(pdev);
2399
James Smart92d7f7b2007-06-17 19:56:38 -05002400 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002401 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002402 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002403
James Smart9b379602008-04-07 10:16:00 -04002404 /* Enable configured interrupt method */
2405 phba->intr_type = NONE;
2406 if (phba->cfg_use_msi == 2) {
2407 error = lpfc_enable_msix(phba);
2408 if (!error)
2409 phba->intr_type = MSIX;
2410 }
2411
2412 /* Fallback to MSI if MSI-X initialization failed */
2413 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2414 retval = pci_enable_msi(phba->pcidev);
2415 if (!retval)
2416 phba->intr_type = MSI;
2417 else
2418 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2419 "0470 Enable MSI failed, continuing "
2420 "with IRQ\n");
2421 }
2422
2423 /* MSI-X is the only case the doesn't need to call request_irq */
2424 if (phba->intr_type != MSIX) {
2425 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2426 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2427 if (retval) {
2428 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2429 "0471 Enable interrupt handler "
2430 "failed\n");
2431 } else if (phba->intr_type != MSI)
2432 phba->intr_type = INTx;
2433 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06002434
2435 /* Take device offline; this will perform cleanup */
2436 lpfc_offline(phba);
2437 lpfc_sli_brdrestart(phba);
2438
2439 return PCI_ERS_RESULT_RECOVERED;
2440}
2441
2442/**
2443 * lpfc_io_resume - called when traffic can start flowing again.
2444 * @pdev: Pointer to PCI device
2445 *
2446 * This callback is called when the error recovery driver tells us that
2447 * its OK to resume normal operation.
2448 */
2449static void lpfc_io_resume(struct pci_dev *pdev)
2450{
James Smart51ef4c22007-08-02 11:10:31 -04002451 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2452 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002453
James Smart58da1ff2008-04-07 10:15:56 -04002454 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002455}
2456
dea31012005-04-17 16:05:31 -05002457static struct pci_device_id lpfc_id_table[] = {
2458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2459 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2461 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2463 PCI_ANY_ID, PCI_ANY_ID, },
2464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2465 PCI_ANY_ID, PCI_ANY_ID, },
2466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2467 PCI_ANY_ID, PCI_ANY_ID, },
2468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2469 PCI_ANY_ID, PCI_ANY_ID, },
2470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2471 PCI_ANY_ID, PCI_ANY_ID, },
2472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2473 PCI_ANY_ID, PCI_ANY_ID, },
2474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2475 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2477 PCI_ANY_ID, PCI_ANY_ID, },
2478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2479 PCI_ANY_ID, PCI_ANY_ID, },
2480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2481 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2483 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2485 PCI_ANY_ID, PCI_ANY_ID, },
2486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2487 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2489 PCI_ANY_ID, PCI_ANY_ID, },
2490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2491 PCI_ANY_ID, PCI_ANY_ID, },
2492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2493 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2495 PCI_ANY_ID, PCI_ANY_ID, },
2496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2497 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2499 PCI_ANY_ID, PCI_ANY_ID, },
2500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2501 PCI_ANY_ID, PCI_ANY_ID, },
2502 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2503 PCI_ANY_ID, PCI_ANY_ID, },
2504 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2505 PCI_ANY_ID, PCI_ANY_ID, },
2506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2507 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002508 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2509 PCI_ANY_ID, PCI_ANY_ID, },
2510 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2511 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002512 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2513 PCI_ANY_ID, PCI_ANY_ID, },
2514 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2515 PCI_ANY_ID, PCI_ANY_ID, },
2516 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2517 PCI_ANY_ID, PCI_ANY_ID, },
2518 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2519 PCI_ANY_ID, PCI_ANY_ID, },
2520 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2521 PCI_ANY_ID, PCI_ANY_ID, },
2522 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2523 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002524 { 0 }
2525};
2526
2527MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2528
Linas Vepstas8d63f372007-02-14 14:28:36 -06002529static struct pci_error_handlers lpfc_err_handler = {
2530 .error_detected = lpfc_io_error_detected,
2531 .slot_reset = lpfc_io_slot_reset,
2532 .resume = lpfc_io_resume,
2533};
2534
dea31012005-04-17 16:05:31 -05002535static struct pci_driver lpfc_driver = {
2536 .name = LPFC_DRIVER_NAME,
2537 .id_table = lpfc_id_table,
2538 .probe = lpfc_pci_probe_one,
2539 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002540 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002541};
2542
2543static int __init
2544lpfc_init(void)
2545{
2546 int error = 0;
2547
2548 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002549 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002550
James Smart7ee5d432007-10-27 13:37:17 -04002551 if (lpfc_enable_npiv) {
2552 lpfc_transport_functions.vport_create = lpfc_vport_create;
2553 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2554 }
dea31012005-04-17 16:05:31 -05002555 lpfc_transport_template =
2556 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002557 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002558 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002559 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002560 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002561 fc_attach_transport(&lpfc_vport_transport_functions);
2562 if (lpfc_vport_transport_template == NULL) {
2563 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002564 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002565 }
James Smart7ee5d432007-10-27 13:37:17 -04002566 }
dea31012005-04-17 16:05:31 -05002567 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002568 if (error) {
dea31012005-04-17 16:05:31 -05002569 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002570 fc_release_transport(lpfc_vport_transport_template);
2571 }
dea31012005-04-17 16:05:31 -05002572
2573 return error;
2574}
2575
2576static void __exit
2577lpfc_exit(void)
2578{
2579 pci_unregister_driver(&lpfc_driver);
2580 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002581 if (lpfc_enable_npiv)
2582 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002583}
2584
2585module_init(lpfc_init);
2586module_exit(lpfc_exit);
2587MODULE_LICENSE("GPL");
2588MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2589MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2590MODULE_VERSION("0:" LPFC_DRIVER_VERSION);