blob: fa757b251f8287505a21f271897598ae0141d3ea [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 Smarted957682007-06-17 19:56:37 -0500148 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
149 return -EINVAL;
150
dea31012005-04-17 16:05:31 -0500151 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500152 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500153 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500154 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
155 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
156 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
157 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500158 vp->rev.biuRev = mb->un.varRdRev.biuRev;
159 vp->rev.smRev = mb->un.varRdRev.smRev;
160 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
161 vp->rev.endecRev = mb->un.varRdRev.endecRev;
162 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
163 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
164 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
165 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
166 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
167 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
168
James Smart92d7f7b2007-06-17 19:56:38 -0500169 /* If the sli feature level is less then 9, we must
170 * tear down all RPIs and VPIs on link down if NPIV
171 * is enabled.
172 */
173 if (vp->rev.feaLevelHigh < 9)
174 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
175
dea31012005-04-17 16:05:31 -0500176 if (lpfc_is_LC_HBA(phba->pcidev->device))
177 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
178 sizeof (phba->RandomData));
179
dea31012005-04-17 16:05:31 -0500180 /* Get adapter VPD information */
181 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
182 if (!pmb->context2)
183 goto out_free_mbox;
184 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
185 if (!lpfc_vpd_data)
186 goto out_free_context2;
187
188 do {
189 lpfc_dump_mem(phba, pmb, offset);
190 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
191
192 if (rc != MBX_SUCCESS) {
193 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400194 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500195 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500196 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500197 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500198 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500199 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
200 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
dea31012005-04-17 16:05:31 -0500201 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500202 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500203 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500204 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
205 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500206
207 kfree(lpfc_vpd_data);
208out_free_context2:
209 kfree(pmb->context2);
210out_free_mbox:
211 mempool_free(pmb, phba->mbox_mem_pool);
212 return 0;
213}
214
James Smart57127f12007-10-27 13:37:05 -0400215/* Completion handler for config async event mailbox command. */
216static void
217lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
218{
219 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
220 phba->temp_sensor_support = 1;
221 else
222 phba->temp_sensor_support = 0;
223 mempool_free(pmboxq, phba->mbox_mem_pool);
224 return;
225}
226
dea31012005-04-17 16:05:31 -0500227/************************************************************************/
228/* */
229/* lpfc_config_port_post */
230/* This routine will do LPFC initialization after the */
231/* CONFIG_PORT mailbox command. This will be initialized */
232/* as a SLI layer callback routine. */
233/* This routine returns 0 on success. Any other return value */
234/* indicates an error. */
235/* */
236/************************************************************************/
237int
James Smart2e0fef82007-06-17 19:56:36 -0500238lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500239{
James Smart2e0fef82007-06-17 19:56:36 -0500240 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500241 LPFC_MBOXQ_t *pmb;
242 MAILBOX_t *mb;
243 struct lpfc_dmabuf *mp;
244 struct lpfc_sli *psli = &phba->sli;
245 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500246 int i, j;
247 int rc;
dea31012005-04-17 16:05:31 -0500248
James Smart7af67052007-10-27 13:38:11 -0400249 spin_lock_irq(&phba->hbalock);
250 /*
251 * If the Config port completed correctly the HBA is not
252 * over heated any more.
253 */
254 if (phba->over_temp_state == HBA_OVER_TEMP)
255 phba->over_temp_state = HBA_NORMAL_TEMP;
256 spin_unlock_irq(&phba->hbalock);
257
dea31012005-04-17 16:05:31 -0500258 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
259 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500260 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500261 return -ENOMEM;
262 }
263 mb = &pmb->mb;
264
dea31012005-04-17 16:05:31 -0500265 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500266 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500267 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500268 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400270 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500271 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500272 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500273 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500274 mp = (struct lpfc_dmabuf *) pmb->context1;
275 mempool_free( pmb, phba->mbox_mem_pool);
276 lpfc_mbuf_free(phba, mp->virt, mp->phys);
277 kfree(mp);
278 return -EIO;
279 }
280
281 mp = (struct lpfc_dmabuf *) pmb->context1;
282
James Smart2e0fef82007-06-17 19:56:36 -0500283 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500284 lpfc_mbuf_free(phba, mp->virt, mp->phys);
285 kfree(mp);
286 pmb->context1 = NULL;
287
James Smarta12e07b2006-12-02 13:35:30 -0500288 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500289 u64_to_wwn(phba->cfg_soft_wwnn,
290 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400291 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500292 u64_to_wwn(phba->cfg_soft_wwpn,
293 vport->fc_sparam.portName.u.wwn);
294 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500295 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500296 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500297 sizeof (struct lpfc_name));
298 /* If no serial number in VPD data, use low 6 bytes of WWNN */
299 /* This should be consolidated into parse_vpd ? - mr */
300 if (phba->SerialNumber[0] == 0) {
301 uint8_t *outptr;
302
James Smart2e0fef82007-06-17 19:56:36 -0500303 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500304 for (i = 0; i < 12; i++) {
305 status = *outptr++;
306 j = ((status & 0xf0) >> 4);
307 if (j <= 9)
308 phba->SerialNumber[i] =
309 (char)((uint8_t) 0x30 + (uint8_t) j);
310 else
311 phba->SerialNumber[i] =
312 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
313 i++;
314 j = (status & 0xf);
315 if (j <= 9)
316 phba->SerialNumber[i] =
317 (char)((uint8_t) 0x30 + (uint8_t) j);
318 else
319 phba->SerialNumber[i] =
320 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
321 }
322 }
323
dea31012005-04-17 16:05:31 -0500324 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500325 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500326 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400328 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500329 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500330 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500331 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500332 mempool_free( pmb, phba->mbox_mem_pool);
333 return -EIO;
334 }
335
336 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
337 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
338 phba->cfg_hba_queue_depth =
339 mb->un.varRdConfig.max_xri + 1;
340
341 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500342
343 /* Get the default values for Model Name and Description */
344 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
345
346 if ((phba->cfg_link_speed > LINK_SPEED_10G)
347 || ((phba->cfg_link_speed == LINK_SPEED_1G)
348 && !(phba->lmt & LMT_1Gb))
349 || ((phba->cfg_link_speed == LINK_SPEED_2G)
350 && !(phba->lmt & LMT_2Gb))
351 || ((phba->cfg_link_speed == LINK_SPEED_4G)
352 && !(phba->lmt & LMT_4Gb))
353 || ((phba->cfg_link_speed == LINK_SPEED_8G)
354 && !(phba->lmt & LMT_8Gb))
355 || ((phba->cfg_link_speed == LINK_SPEED_10G)
356 && !(phba->lmt & LMT_10Gb))) {
357 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500358 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400359 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500360 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500361 phba->cfg_link_speed);
362 phba->cfg_link_speed = LINK_SPEED_AUTO;
363 }
364
James Smart2e0fef82007-06-17 19:56:36 -0500365 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500366
James Smart0b727fe2007-10-27 13:37:25 -0400367 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500368 if (psli->ring[psli->extra_ring].cmdringaddr)
369 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500370 if (psli->ring[psli->fcp_ring].cmdringaddr)
371 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
372 if (psli->ring[psli->next_ring].cmdringaddr)
373 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
374
375 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500376 if (phba->sli_rev != 3)
377 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500378
379 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500380 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500381 status = readl(phba->HCregaddr);
382 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
383 if (psli->num_rings > 0)
384 status |= HC_R0INT_ENA;
385 if (psli->num_rings > 1)
386 status |= HC_R1INT_ENA;
387 if (psli->num_rings > 2)
388 status |= HC_R2INT_ENA;
389 if (psli->num_rings > 3)
390 status |= HC_R3INT_ENA;
391
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500392 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
393 (phba->cfg_poll & DISABLE_FCP_RING_INT))
394 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
395
dea31012005-04-17 16:05:31 -0500396 writel(status, phba->HCregaddr);
397 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500398 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500399
400 /*
401 * Setup the ring 0 (els) timeout handler
402 */
403 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500404 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500405 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
406 phba->hb_outstanding = 0;
407 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500408
409 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
410 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500411 pmb->vport = vport;
James Smart8aee9182006-08-31 12:27:57 -0400412 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400413 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400414 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400416 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500417 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500418 mb->mbxCommand, mb->mbxStatus);
419
420 /* Clear all interrupt enable conditions */
421 writel(0, phba->HCregaddr);
422 readl(phba->HCregaddr); /* flush */
423 /* Clear all pending interrupts */
424 writel(0xffffffff, phba->HAregaddr);
425 readl(phba->HAregaddr); /* flush */
426
James Smart2e0fef82007-06-17 19:56:36 -0500427 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400428 if (rc != MBX_BUSY)
429 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500430 return -EIO;
431 }
432 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400433 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
434 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
435 pmb->mbox_cmpl = lpfc_config_async_cmpl;
436 pmb->vport = phba->pport;
437 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500438
James Smart57127f12007-10-27 13:37:05 -0400439 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
440 lpfc_printf_log(phba,
441 KERN_ERR,
442 LOG_INIT,
443 "0456 Adapter failed to issue "
444 "ASYNCEVT_ENABLE mbox status x%x \n.",
445 rc);
446 mempool_free(pmb, phba->mbox_mem_pool);
447 }
James Smartce8b3ce2006-07-06 15:50:36 -0400448 return (0);
449}
450
dea31012005-04-17 16:05:31 -0500451/************************************************************************/
452/* */
453/* lpfc_hba_down_prep */
454/* This routine will do LPFC uninitialization before the */
455/* HBA is reset when bringing down the SLI Layer. This will be */
456/* initialized as a SLI layer callback routine. */
457/* This routine returns 0 on success. Any other return value */
458/* indicates an error. */
459/* */
460/************************************************************************/
461int
James Smart2e0fef82007-06-17 19:56:36 -0500462lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500463{
James Smart1b32f6a2008-02-08 18:49:39 -0500464 struct lpfc_vport **vports;
465 int i;
dea31012005-04-17 16:05:31 -0500466 /* Disable interrupts */
467 writel(0, phba->HCregaddr);
468 readl(phba->HCregaddr); /* flush */
469
James Smart1b32f6a2008-02-08 18:49:39 -0500470 if (phba->pport->load_flag & FC_UNLOADING)
471 lpfc_cleanup_discovery_resources(phba->pport);
472 else {
473 vports = lpfc_create_vport_work_array(phba);
474 if (vports != NULL)
475 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
476 lpfc_cleanup_discovery_resources(vports[i]);
477 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500478 }
479 return 0;
dea31012005-04-17 16:05:31 -0500480}
481
482/************************************************************************/
483/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500484/* lpfc_hba_down_post */
485/* This routine will do uninitialization after the HBA is reset */
486/* when bringing down the SLI Layer. */
487/* This routine returns 0 on success. Any other return value */
488/* indicates an error. */
489/* */
490/************************************************************************/
491int
James Smart2e0fef82007-06-17 19:56:36 -0500492lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500493{
494 struct lpfc_sli *psli = &phba->sli;
495 struct lpfc_sli_ring *pring;
496 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500497 struct lpfc_iocbq *iocb;
498 IOCB_t *cmd = NULL;
499 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500500 int i;
501
James Smart92d7f7b2007-06-17 19:56:38 -0500502 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
503 lpfc_sli_hbqbuf_free_all(phba);
504 else {
505 /* Cleanup preposted buffers on the ELS ring */
506 pring = &psli->ring[LPFC_ELS_RING];
507 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
508 list_del(&mp->list);
509 pring->postbufq_cnt--;
510 lpfc_mbuf_free(phba, mp->virt, mp->phys);
511 kfree(mp);
512 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500513 }
514
James Smart09372822008-01-11 01:52:54 -0500515 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500516 for (i = 0; i < psli->num_rings; i++) {
517 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500518
519 /* At this point in time the HBA is either reset or DOA. Either
520 * way, nothing should be on txcmplq as it will NEVER complete.
521 */
522 list_splice_init(&pring->txcmplq, &completions);
523 pring->txcmplq_cnt = 0;
524 spin_unlock_irq(&phba->hbalock);
525
526 while (!list_empty(&completions)) {
527 iocb = list_get_first(&completions, struct lpfc_iocbq,
528 list);
529 cmd = &iocb->iocb;
530 list_del_init(&iocb->list);
531
532 if (!iocb->iocb_cmpl)
533 lpfc_sli_release_iocbq(phba, iocb);
534 else {
535 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
536 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
537 (iocb->iocb_cmpl) (phba, iocb, iocb);
538 }
539 }
540
Jamie Wellnitz41415862006-02-28 19:25:27 -0500541 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500542 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500543 }
James Smart09372822008-01-11 01:52:54 -0500544 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500545
546 return 0;
547}
548
James Smart858c9f62007-06-17 19:56:39 -0500549/* HBA heart beat timeout handler */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100550static void
James Smart858c9f62007-06-17 19:56:39 -0500551lpfc_hb_timeout(unsigned long ptr)
552{
553 struct lpfc_hba *phba;
554 unsigned long iflag;
555
556 phba = (struct lpfc_hba *)ptr;
557 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
558 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
559 phba->pport->work_port_events |= WORKER_HB_TMO;
560 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
561
James Smart58da1ff2008-04-07 10:15:56 -0400562 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart858c9f62007-06-17 19:56:39 -0500563 if (phba->work_wait)
564 wake_up(phba->work_wait);
James Smart58da1ff2008-04-07 10:15:56 -0400565 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart858c9f62007-06-17 19:56:39 -0500566 return;
567}
568
569static void
570lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
571{
572 unsigned long drvr_flag;
573
574 spin_lock_irqsave(&phba->hbalock, drvr_flag);
575 phba->hb_outstanding = 0;
576 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
577
578 mempool_free(pmboxq, phba->mbox_mem_pool);
579 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
580 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400581 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500582 mod_timer(&phba->hb_tmofunc,
583 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
584 return;
585}
586
587void
588lpfc_hb_timeout_handler(struct lpfc_hba *phba)
589{
590 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500591 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500592 int retval;
593 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500594 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500595
596 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400597 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500598 (phba->pport->fc_flag & FC_OFFLINE_MODE))
599 return;
600
601 spin_lock_irq(&phba->pport->work_port_lock);
602 /* If the timer is already canceled do nothing */
603 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
604 spin_unlock_irq(&phba->pport->work_port_lock);
605 return;
606 }
607
608 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
609 jiffies)) {
610 spin_unlock_irq(&phba->pport->work_port_lock);
611 if (!phba->hb_outstanding)
612 mod_timer(&phba->hb_tmofunc,
613 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
614 else
615 mod_timer(&phba->hb_tmofunc,
616 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
617 return;
618 }
619 spin_unlock_irq(&phba->pport->work_port_lock);
620
James Smart0ff10d42008-01-11 01:52:36 -0500621 if (phba->elsbuf_cnt &&
622 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
623 spin_lock_irq(&phba->hbalock);
624 list_splice_init(&phba->elsbuf, &completions);
625 phba->elsbuf_cnt = 0;
626 phba->elsbuf_prev_cnt = 0;
627 spin_unlock_irq(&phba->hbalock);
628
629 while (!list_empty(&completions)) {
630 list_remove_head(&completions, buf_ptr,
631 struct lpfc_dmabuf, list);
632 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
633 kfree(buf_ptr);
634 }
635 }
636 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
637
James Smart858c9f62007-06-17 19:56:39 -0500638 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500639 if (phba->cfg_enable_hba_heartbeat) {
640 if (!phba->hb_outstanding) {
641 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
642 if (!pmboxq) {
643 mod_timer(&phba->hb_tmofunc,
644 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
645 return;
646 }
647
648 lpfc_heart_beat(phba, pmboxq);
649 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
650 pmboxq->vport = phba->pport;
651 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
652
653 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
654 mempool_free(pmboxq, phba->mbox_mem_pool);
655 mod_timer(&phba->hb_tmofunc,
656 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
657 return;
658 }
James Smart858c9f62007-06-17 19:56:39 -0500659 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500660 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
661 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500662 return;
James Smart13815c82008-01-11 01:52:48 -0500663 } else {
664 /*
665 * If heart beat timeout called with hb_outstanding set
666 * we need to take the HBA offline.
667 */
668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
669 "0459 Adapter heartbeat failure, "
670 "taking this port offline.\n");
671
672 spin_lock_irq(&phba->hbalock);
673 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
674 spin_unlock_irq(&phba->hbalock);
675
676 lpfc_offline_prep(phba);
677 lpfc_offline(phba);
678 lpfc_unblock_mgmt_io(phba);
679 phba->link_state = LPFC_HBA_ERROR;
680 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500681 }
James Smart858c9f62007-06-17 19:56:39 -0500682 }
683}
684
James Smart09372822008-01-11 01:52:54 -0500685static void
686lpfc_offline_eratt(struct lpfc_hba *phba)
687{
688 struct lpfc_sli *psli = &phba->sli;
689
690 spin_lock_irq(&phba->hbalock);
691 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
692 spin_unlock_irq(&phba->hbalock);
693 lpfc_offline_prep(phba);
694
695 lpfc_offline(phba);
696 lpfc_reset_barrier(phba);
697 lpfc_sli_brdreset(phba);
698 lpfc_hba_down_post(phba);
699 lpfc_sli_brdready(phba, HS_MBRDY);
700 lpfc_unblock_mgmt_io(phba);
701 phba->link_state = LPFC_HBA_ERROR;
702 return;
703}
704
Jamie Wellnitz41415862006-02-28 19:25:27 -0500705/************************************************************************/
706/* */
dea31012005-04-17 16:05:31 -0500707/* lpfc_handle_eratt */
708/* This routine will handle processing a Host Attention */
709/* Error Status event. This will be initialized */
710/* as a SLI layer callback routine. */
711/* */
712/************************************************************************/
713void
James Smart2e0fef82007-06-17 19:56:36 -0500714lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500715{
James Smart2e0fef82007-06-17 19:56:36 -0500716 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500717 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500718 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400719 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400720 unsigned long temperature;
721 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500722 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -0500723
Linas Vepstas8d63f372007-02-14 14:28:36 -0600724 /* If the pci channel is offline, ignore possible errors,
725 * since we cannot communicate with the pci card anyway. */
726 if (pci_channel_offline(phba->pcidev))
727 return;
James Smart13815c82008-01-11 01:52:48 -0500728 /* If resets are disabled then leave the HBA alone and return */
729 if (!phba->cfg_enable_hba_reset)
730 return;
dea31012005-04-17 16:05:31 -0500731
James Smart97eab632008-04-07 10:16:05 -0400732 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500733 /* Re-establishing Link */
734 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400735 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500736 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400737 phba->work_hs,
dea31012005-04-17 16:05:31 -0500738 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400739
James Smart92d7f7b2007-06-17 19:56:38 -0500740 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500741 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500742 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500743
744 /*
745 * Firmware stops when it triggled erratt with HS_FFER6.
746 * That could cause the I/Os dropped by the firmware.
747 * Error iocb (I/O) on txcmplq and let the SCSI layer
748 * retry it after re-establishing link.
749 */
750 pring = &psli->ring[psli->fcp_ring];
751 lpfc_sli_abort_iocb_ring(phba, pring);
752
dea31012005-04-17 16:05:31 -0500753 /*
754 * There was a firmware error. Take the hba offline and then
755 * attempt to restart it.
756 */
James Smart46fa3112007-04-25 09:51:45 -0400757 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500758 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500759 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500760 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -0400761 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500762 return;
763 }
James Smart46fa3112007-04-25 09:51:45 -0400764 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400765 } else if (phba->work_hs & HS_CRIT_TEMP) {
766 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
767 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
768 temp_event_data.event_code = LPFC_CRIT_TEMP;
769 temp_event_data.data = (uint32_t)temperature;
770
771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
772 "0459 Adapter maximum temperature exceeded "
773 "(%ld), taking this port offline "
774 "Data: x%x x%x x%x\n",
775 temperature, phba->work_hs,
776 phba->work_status[0], phba->work_status[1]);
777
778 shost = lpfc_shost_from_vport(phba->pport);
779 fc_host_post_vendor_event(shost, fc_get_event_number(),
780 sizeof(temp_event_data),
781 (char *) &temp_event_data,
782 SCSI_NL_VID_TYPE_PCI
783 | PCI_VENDOR_ID_EMULEX);
784
James Smart7af67052007-10-27 13:38:11 -0400785 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400786 phba->over_temp_state = HBA_OVER_TEMP;
787 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500788 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400789
dea31012005-04-17 16:05:31 -0500790 } else {
791 /* The if clause above forces this code path when the status
792 * failure is a value other than FFER6. Do not call the offline
793 * twice. This is the adapter hardware error path.
794 */
795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400796 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500797 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400798 phba->work_hs,
dea31012005-04-17 16:05:31 -0500799 phba->work_status[0], phba->work_status[1]);
800
James Smartd2873e42006-08-18 17:46:43 -0400801 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500802 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500803 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400804 sizeof(event_data), (char *) &event_data,
805 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
806
James Smart09372822008-01-11 01:52:54 -0500807 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500808 }
809}
810
811/************************************************************************/
812/* */
813/* lpfc_handle_latt */
814/* This routine will handle processing a Host Attention */
815/* Link Status event. This will be initialized */
816/* as a SLI layer callback routine. */
817/* */
818/************************************************************************/
819void
James Smart2e0fef82007-06-17 19:56:36 -0500820lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500821{
James Smart2e0fef82007-06-17 19:56:36 -0500822 struct lpfc_vport *vport = phba->pport;
823 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500824 LPFC_MBOXQ_t *pmb;
825 volatile uint32_t control;
826 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500827 int rc = 0;
dea31012005-04-17 16:05:31 -0500828
829 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500830 if (!pmb) {
831 rc = 1;
dea31012005-04-17 16:05:31 -0500832 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500833 }
dea31012005-04-17 16:05:31 -0500834
835 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500836 if (!mp) {
837 rc = 2;
dea31012005-04-17 16:05:31 -0500838 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500839 }
dea31012005-04-17 16:05:31 -0500840
841 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500842 if (!mp->virt) {
843 rc = 3;
dea31012005-04-17 16:05:31 -0500844 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500845 }
dea31012005-04-17 16:05:31 -0500846
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500847 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400848 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500849
850 psli->slistat.link_event++;
851 lpfc_read_la(phba, pmb, mp);
852 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500853 pmb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400854 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500855 if (rc == MBX_NOT_FINISHED) {
856 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500857 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500858 }
dea31012005-04-17 16:05:31 -0500859
860 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500861 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500862 writel(HA_LATT, phba->HAregaddr);
863 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500864 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500865
866 return;
867
James Smart14691152006-12-02 13:34:28 -0500868lpfc_handle_latt_free_mbuf:
869 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500870lpfc_handle_latt_free_mp:
871 kfree(mp);
872lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400873 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500874lpfc_handle_latt_err_exit:
875 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500876 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500877 psli->sli_flag |= LPFC_PROCESS_LA;
878 control = readl(phba->HCregaddr);
879 control |= HC_LAINT_ENA;
880 writel(control, phba->HCregaddr);
881 readl(phba->HCregaddr); /* flush */
882
883 /* Clear Link Attention in HA REG */
884 writel(HA_LATT, phba->HAregaddr);
885 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500886 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500887 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500888 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500889
James Smart09372822008-01-11 01:52:54 -0500890 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
891 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500892
893 return;
894}
895
896/************************************************************************/
897/* */
898/* lpfc_parse_vpd */
899/* This routine will parse the VPD data */
900/* */
901/************************************************************************/
902static int
James Smart2e0fef82007-06-17 19:56:36 -0500903lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500904{
905 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500906 int Length;
dea31012005-04-17 16:05:31 -0500907 int i, j;
908 int finished = 0;
909 int index = 0;
910
911 if (!vpd)
912 return 0;
913
914 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500915 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400916 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500917 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
918 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500919 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500920 switch (vpd[index]) {
921 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500922 case 0x91:
dea31012005-04-17 16:05:31 -0500923 index += 1;
924 lenlo = vpd[index];
925 index += 1;
926 lenhi = vpd[index];
927 index += 1;
928 i = ((((unsigned short)lenhi) << 8) + lenlo);
929 index += i;
930 break;
931 case 0x90:
932 index += 1;
933 lenlo = vpd[index];
934 index += 1;
935 lenhi = vpd[index];
936 index += 1;
937 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500938 if (Length > len - index)
939 Length = len - index;
dea31012005-04-17 16:05:31 -0500940 while (Length > 0) {
941 /* Look for Serial Number */
942 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
943 index += 2;
944 i = vpd[index];
945 index += 1;
946 j = 0;
947 Length -= (3+i);
948 while(i--) {
949 phba->SerialNumber[j++] = vpd[index++];
950 if (j == 31)
951 break;
952 }
953 phba->SerialNumber[j] = 0;
954 continue;
955 }
956 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
957 phba->vpd_flag |= VPD_MODEL_DESC;
958 index += 2;
959 i = vpd[index];
960 index += 1;
961 j = 0;
962 Length -= (3+i);
963 while(i--) {
964 phba->ModelDesc[j++] = vpd[index++];
965 if (j == 255)
966 break;
967 }
968 phba->ModelDesc[j] = 0;
969 continue;
970 }
971 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
972 phba->vpd_flag |= VPD_MODEL_NAME;
973 index += 2;
974 i = vpd[index];
975 index += 1;
976 j = 0;
977 Length -= (3+i);
978 while(i--) {
979 phba->ModelName[j++] = vpd[index++];
980 if (j == 79)
981 break;
982 }
983 phba->ModelName[j] = 0;
984 continue;
985 }
986 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
987 phba->vpd_flag |= VPD_PROGRAM_TYPE;
988 index += 2;
989 i = vpd[index];
990 index += 1;
991 j = 0;
992 Length -= (3+i);
993 while(i--) {
994 phba->ProgramType[j++] = vpd[index++];
995 if (j == 255)
996 break;
997 }
998 phba->ProgramType[j] = 0;
999 continue;
1000 }
1001 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1002 phba->vpd_flag |= VPD_PORT;
1003 index += 2;
1004 i = vpd[index];
1005 index += 1;
1006 j = 0;
1007 Length -= (3+i);
1008 while(i--) {
1009 phba->Port[j++] = vpd[index++];
1010 if (j == 19)
1011 break;
1012 }
1013 phba->Port[j] = 0;
1014 continue;
1015 }
1016 else {
1017 index += 2;
1018 i = vpd[index];
1019 index += 1;
1020 index += i;
1021 Length -= (3 + i);
1022 }
1023 }
1024 finished = 0;
1025 break;
1026 case 0x78:
1027 finished = 1;
1028 break;
1029 default:
1030 index ++;
1031 break;
1032 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001033 }
dea31012005-04-17 16:05:31 -05001034
1035 return(1);
1036}
1037
1038static void
James Smart2e0fef82007-06-17 19:56:36 -05001039lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001040{
1041 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001042 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001043 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001044 struct {
1045 char * name;
1046 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001047 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001048 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001049
1050 if (mdp && mdp[0] != '\0'
1051 && descp && descp[0] != '\0')
1052 return;
1053
1054 if (phba->lmt & LMT_10Gb)
1055 max_speed = 10;
1056 else if (phba->lmt & LMT_8Gb)
1057 max_speed = 8;
1058 else if (phba->lmt & LMT_4Gb)
1059 max_speed = 4;
1060 else if (phba->lmt & LMT_2Gb)
1061 max_speed = 2;
1062 else
1063 max_speed = 1;
dea31012005-04-17 16:05:31 -05001064
1065 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001066
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001067 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001068 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001069 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001070 break;
dea31012005-04-17 16:05:31 -05001071 case PCI_DEVICE_ID_SUPERFLY:
1072 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001073 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001074 else
James Smart18a3b592006-12-02 13:35:08 -05001075 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001076 break;
1077 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001078 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001079 break;
1080 case PCI_DEVICE_ID_CENTAUR:
1081 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001082 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001083 else
James Smart18a3b592006-12-02 13:35:08 -05001084 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001085 break;
1086 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001087 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001088 break;
1089 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001090 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001091 break;
1092 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001093 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001094 break;
1095 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001096 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001097 break;
1098 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001099 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001100 break;
1101 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001102 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001103 break;
1104 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001105 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001106 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001107 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001108 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001109 break;
1110 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001111 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001112 break;
1113 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001114 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001115 break;
1116 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001117 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001118 break;
1119 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001120 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001121 break;
dea31012005-04-17 16:05:31 -05001122 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001123 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001124 break;
1125 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001126 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001127 break;
1128 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001129 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001130 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001131 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001132 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001133 break;
1134 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001135 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001136 break;
dea31012005-04-17 16:05:31 -05001137 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001138 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001139 break;
1140 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001141 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001142 break;
1143 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001144 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001145 break;
1146 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001147 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001148 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001149 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001150 m = (typeof(m)){"LP11000-S", max_speed,
1151 "PCI-X2"};
1152 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001153 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001154 m = (typeof(m)){"LPe11000-S", max_speed,
1155 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001156 break;
James Smartb87eab32007-04-25 09:53:28 -04001157 case PCI_DEVICE_ID_SAT:
1158 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1159 break;
1160 case PCI_DEVICE_ID_SAT_MID:
1161 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1162 break;
1163 case PCI_DEVICE_ID_SAT_SMB:
1164 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1165 break;
1166 case PCI_DEVICE_ID_SAT_DCSP:
1167 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1168 break;
1169 case PCI_DEVICE_ID_SAT_SCSP:
1170 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1171 break;
1172 case PCI_DEVICE_ID_SAT_S:
1173 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1174 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001175 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001176 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001177 break;
dea31012005-04-17 16:05:31 -05001178 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001179
1180 if (mdp && mdp[0] == '\0')
1181 snprintf(mdp, 79,"%s", m.name);
1182 if (descp && descp[0] == '\0')
1183 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001184 "Emulex %s %dGb %s Fibre Channel Adapter",
1185 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001186}
1187
1188/**************************************************/
1189/* lpfc_post_buffer */
1190/* */
1191/* This routine will post count buffers to the */
1192/* ring with the QUE_RING_BUF_CN command. This */
1193/* allows 3 buffers / command to be posted. */
1194/* Returns the number of buffers NOT posted. */
1195/**************************************************/
1196int
James Smart2e0fef82007-06-17 19:56:36 -05001197lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -05001198 int type)
1199{
1200 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001201 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001202 struct lpfc_dmabuf *mp1, *mp2;
1203
1204 cnt += pring->missbufcnt;
1205
1206 /* While there are buffers to post */
1207 while (cnt > 0) {
1208 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001209 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001210 if (iocb == NULL) {
1211 pring->missbufcnt = cnt;
1212 return cnt;
1213 }
dea31012005-04-17 16:05:31 -05001214 icmd = &iocb->iocb;
1215
1216 /* 2 buffers can be posted per command */
1217 /* Allocate buffer to post */
1218 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1219 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001220 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1221 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001222 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001223 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001224 pring->missbufcnt = cnt;
1225 return cnt;
1226 }
1227
1228 INIT_LIST_HEAD(&mp1->list);
1229 /* Allocate buffer to post */
1230 if (cnt > 1) {
1231 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1232 if (mp2)
1233 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1234 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001235 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001236 kfree(mp2);
dea31012005-04-17 16:05:31 -05001237 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1238 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001239 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001240 pring->missbufcnt = cnt;
1241 return cnt;
1242 }
1243
1244 INIT_LIST_HEAD(&mp2->list);
1245 } else {
1246 mp2 = NULL;
1247 }
1248
1249 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1250 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1251 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1252 icmd->ulpBdeCount = 1;
1253 cnt--;
1254 if (mp2) {
1255 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1256 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1257 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1258 cnt--;
1259 icmd->ulpBdeCount = 2;
1260 }
1261
1262 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1263 icmd->ulpLe = 1;
1264
dea31012005-04-17 16:05:31 -05001265 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1266 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1267 kfree(mp1);
1268 cnt++;
1269 if (mp2) {
1270 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1271 kfree(mp2);
1272 cnt++;
1273 }
James Bottomley604a3e32005-10-29 10:28:33 -05001274 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001275 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001276 return cnt;
1277 }
dea31012005-04-17 16:05:31 -05001278 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001279 if (mp2)
dea31012005-04-17 16:05:31 -05001280 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001281 }
1282 pring->missbufcnt = 0;
1283 return 0;
1284}
1285
1286/************************************************************************/
1287/* */
1288/* lpfc_post_rcv_buf */
1289/* This routine post initial rcv buffers to the configured rings */
1290/* */
1291/************************************************************************/
1292static int
James Smart2e0fef82007-06-17 19:56:36 -05001293lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001294{
1295 struct lpfc_sli *psli = &phba->sli;
1296
1297 /* Ring 0, ELS / CT buffers */
1298 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1299 /* Ring 2 - FCP no buffers needed */
1300
1301 return 0;
1302}
1303
1304#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1305
1306/************************************************************************/
1307/* */
1308/* lpfc_sha_init */
1309/* */
1310/************************************************************************/
1311static void
1312lpfc_sha_init(uint32_t * HashResultPointer)
1313{
1314 HashResultPointer[0] = 0x67452301;
1315 HashResultPointer[1] = 0xEFCDAB89;
1316 HashResultPointer[2] = 0x98BADCFE;
1317 HashResultPointer[3] = 0x10325476;
1318 HashResultPointer[4] = 0xC3D2E1F0;
1319}
1320
1321/************************************************************************/
1322/* */
1323/* lpfc_sha_iterate */
1324/* */
1325/************************************************************************/
1326static void
1327lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1328{
1329 int t;
1330 uint32_t TEMP;
1331 uint32_t A, B, C, D, E;
1332 t = 16;
1333 do {
1334 HashWorkingPointer[t] =
1335 S(1,
1336 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1337 8] ^
1338 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1339 } while (++t <= 79);
1340 t = 0;
1341 A = HashResultPointer[0];
1342 B = HashResultPointer[1];
1343 C = HashResultPointer[2];
1344 D = HashResultPointer[3];
1345 E = HashResultPointer[4];
1346
1347 do {
1348 if (t < 20) {
1349 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1350 } else if (t < 40) {
1351 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1352 } else if (t < 60) {
1353 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1354 } else {
1355 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1356 }
1357 TEMP += S(5, A) + E + HashWorkingPointer[t];
1358 E = D;
1359 D = C;
1360 C = S(30, B);
1361 B = A;
1362 A = TEMP;
1363 } while (++t <= 79);
1364
1365 HashResultPointer[0] += A;
1366 HashResultPointer[1] += B;
1367 HashResultPointer[2] += C;
1368 HashResultPointer[3] += D;
1369 HashResultPointer[4] += E;
1370
1371}
1372
1373/************************************************************************/
1374/* */
1375/* lpfc_challenge_key */
1376/* */
1377/************************************************************************/
1378static void
1379lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1380{
1381 *HashWorking = (*RandomChallenge ^ *HashWorking);
1382}
1383
1384/************************************************************************/
1385/* */
1386/* lpfc_hba_init */
1387/* */
1388/************************************************************************/
1389void
1390lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1391{
1392 int t;
1393 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001394 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001395
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001396 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001397 if (!HashWorking)
1398 return;
1399
dea31012005-04-17 16:05:31 -05001400 HashWorking[0] = HashWorking[78] = *pwwnn++;
1401 HashWorking[1] = HashWorking[79] = *pwwnn;
1402
1403 for (t = 0; t < 7; t++)
1404 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1405
1406 lpfc_sha_init(hbainit);
1407 lpfc_sha_iterate(hbainit, HashWorking);
1408 kfree(HashWorking);
1409}
1410
James Smart87af33f2007-10-27 13:37:43 -04001411void
James Smart2e0fef82007-06-17 19:56:36 -05001412lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001413{
James Smart87af33f2007-10-27 13:37:43 -04001414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001415 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001416 int i = 0;
dea31012005-04-17 16:05:31 -05001417
James Smart87af33f2007-10-27 13:37:43 -04001418 if (phba->link_state > LPFC_LINK_DOWN)
1419 lpfc_port_link_failure(vport);
1420
1421 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001422 if (!NLP_CHK_NODE_ACT(ndlp)) {
1423 ndlp = lpfc_enable_node(vport, ndlp,
1424 NLP_STE_UNUSED_NODE);
1425 if (!ndlp)
1426 continue;
1427 spin_lock_irq(&phba->ndlp_lock);
1428 NLP_SET_FREE_REQ(ndlp);
1429 spin_unlock_irq(&phba->ndlp_lock);
1430 /* Trigger the release of the ndlp memory */
1431 lpfc_nlp_put(ndlp);
1432 continue;
1433 }
1434 spin_lock_irq(&phba->ndlp_lock);
1435 if (NLP_CHK_FREE_REQ(ndlp)) {
1436 /* The ndlp should not be in memory free mode already */
1437 spin_unlock_irq(&phba->ndlp_lock);
1438 continue;
1439 } else
1440 /* Indicate request for freeing ndlp memory */
1441 NLP_SET_FREE_REQ(ndlp);
1442 spin_unlock_irq(&phba->ndlp_lock);
1443
James Smart58da1ff2008-04-07 10:15:56 -04001444 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1445 ndlp->nlp_DID == Fabric_DID) {
1446 /* Just free up ndlp with Fabric_DID for vports */
1447 lpfc_nlp_put(ndlp);
1448 continue;
1449 }
1450
James Smart87af33f2007-10-27 13:37:43 -04001451 if (ndlp->nlp_type & NLP_FABRIC)
1452 lpfc_disc_state_machine(vport, ndlp, NULL,
1453 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001454
James Smart87af33f2007-10-27 13:37:43 -04001455 lpfc_disc_state_machine(vport, ndlp, NULL,
1456 NLP_EVT_DEVICE_RM);
1457 }
1458
James Smarta8adb832007-10-27 13:37:53 -04001459 /* At this point, ALL ndlp's should be gone
1460 * because of the previous NLP_EVT_DEVICE_RM.
1461 * Lets wait for this to happen, if needed.
1462 */
James Smart87af33f2007-10-27 13:37:43 -04001463 while (!list_empty(&vport->fc_nodes)) {
1464
James Smarta8adb832007-10-27 13:37:53 -04001465 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001466 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001467 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001468 list_for_each_entry_safe(ndlp, next_ndlp,
1469 &vport->fc_nodes, nlp_listp) {
1470 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1471 LOG_NODE,
1472 "0282: did:x%x ndlp:x%p "
1473 "usgmap:x%x refcnt:%d\n",
1474 ndlp->nlp_DID, (void *)ndlp,
1475 ndlp->nlp_usg_map,
1476 atomic_read(
1477 &ndlp->kref.refcount));
1478 }
James Smarta8adb832007-10-27 13:37:53 -04001479 break;
James Smart87af33f2007-10-27 13:37:43 -04001480 }
James Smarta8adb832007-10-27 13:37:53 -04001481
1482 /* Wait for any activity on ndlps to settle */
1483 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001484 }
dea31012005-04-17 16:05:31 -05001485 return;
1486}
1487
James Smart92d7f7b2007-06-17 19:56:38 -05001488void
1489lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001490{
James Smart92d7f7b2007-06-17 19:56:38 -05001491 del_timer_sync(&vport->els_tmofunc);
1492 del_timer_sync(&vport->fc_fdmitmo);
1493 lpfc_can_disctmo(vport);
1494 return;
dea31012005-04-17 16:05:31 -05001495}
1496
James Smart2e0fef82007-06-17 19:56:36 -05001497static void
James Smart92d7f7b2007-06-17 19:56:38 -05001498lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001499{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001500 del_timer_sync(&phba->fcp_poll_timer);
James Smart51ef4c22007-08-02 11:10:31 -04001501 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001502 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001503 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001504 phba->hb_outstanding = 0;
1505 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001506 return;
dea31012005-04-17 16:05:31 -05001507}
1508
Adrian Bunka6ababd2007-11-05 18:07:33 +01001509static void
1510lpfc_block_mgmt_io(struct lpfc_hba * phba)
1511{
1512 unsigned long iflag;
1513
1514 spin_lock_irqsave(&phba->hbalock, iflag);
1515 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1516 spin_unlock_irqrestore(&phba->hbalock, iflag);
1517}
1518
dea31012005-04-17 16:05:31 -05001519int
James Smart2e0fef82007-06-17 19:56:36 -05001520lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001521{
James Smart2e0fef82007-06-17 19:56:36 -05001522 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001523 struct lpfc_vport **vports;
1524 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001525
dea31012005-04-17 16:05:31 -05001526 if (!phba)
1527 return 0;
1528
James Smart2e0fef82007-06-17 19:56:36 -05001529 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001530 return 0;
1531
James Smarted957682007-06-17 19:56:37 -05001532 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001533 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001534
James Smart46fa3112007-04-25 09:51:45 -04001535 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001536
James Smart46fa3112007-04-25 09:51:45 -04001537 if (!lpfc_sli_queue_setup(phba)) {
1538 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001539 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001540 }
1541
1542 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1543 lpfc_unblock_mgmt_io(phba);
1544 return 1;
1545 }
dea31012005-04-17 16:05:31 -05001546
James Smart549e55c2007-08-02 11:09:51 -04001547 vports = lpfc_create_vport_work_array(phba);
1548 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001549 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001550 struct Scsi_Host *shost;
1551 shost = lpfc_shost_from_vport(vports[i]);
1552 spin_lock_irq(shost->host_lock);
1553 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1554 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1555 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1556 spin_unlock_irq(shost->host_lock);
1557 }
James Smart09372822008-01-11 01:52:54 -05001558 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001559
James Smart46fa3112007-04-25 09:51:45 -04001560 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001561 return 0;
1562}
1563
James Smart46fa3112007-04-25 09:51:45 -04001564void
James Smart46fa3112007-04-25 09:51:45 -04001565lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1566{
1567 unsigned long iflag;
1568
James Smart2e0fef82007-06-17 19:56:36 -05001569 spin_lock_irqsave(&phba->hbalock, iflag);
1570 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1571 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001572}
1573
1574void
1575lpfc_offline_prep(struct lpfc_hba * phba)
1576{
James Smart2e0fef82007-06-17 19:56:36 -05001577 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001578 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001579 struct lpfc_vport **vports;
1580 int i;
dea31012005-04-17 16:05:31 -05001581
James Smart2e0fef82007-06-17 19:56:36 -05001582 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001583 return;
dea31012005-04-17 16:05:31 -05001584
James Smart46fa3112007-04-25 09:51:45 -04001585 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001586
1587 lpfc_linkdown(phba);
1588
James Smart87af33f2007-10-27 13:37:43 -04001589 /* Issue an unreg_login to all nodes on all vports */
1590 vports = lpfc_create_vport_work_array(phba);
1591 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001592 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001593 struct Scsi_Host *shost;
1594
James Smarta8adb832007-10-27 13:37:53 -04001595 if (vports[i]->load_flag & FC_UNLOADING)
1596 continue;
James Smart87af33f2007-10-27 13:37:43 -04001597 shost = lpfc_shost_from_vport(vports[i]);
1598 list_for_each_entry_safe(ndlp, next_ndlp,
1599 &vports[i]->fc_nodes,
1600 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001601 if (!NLP_CHK_NODE_ACT(ndlp))
1602 continue;
James Smart87af33f2007-10-27 13:37:43 -04001603 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1604 continue;
1605 if (ndlp->nlp_type & NLP_FABRIC) {
1606 lpfc_disc_state_machine(vports[i], ndlp,
1607 NULL, NLP_EVT_DEVICE_RECOVERY);
1608 lpfc_disc_state_machine(vports[i], ndlp,
1609 NULL, NLP_EVT_DEVICE_RM);
1610 }
1611 spin_lock_irq(shost->host_lock);
1612 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1613 spin_unlock_irq(shost->host_lock);
1614 lpfc_unreg_rpi(vports[i], ndlp);
1615 }
1616 }
1617 }
James Smart09372822008-01-11 01:52:54 -05001618 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001619
James Smart46fa3112007-04-25 09:51:45 -04001620 lpfc_sli_flush_mbox_queue(phba);
1621}
1622
1623void
James Smart2e0fef82007-06-17 19:56:36 -05001624lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001625{
James Smart549e55c2007-08-02 11:09:51 -04001626 struct Scsi_Host *shost;
1627 struct lpfc_vport **vports;
1628 int i;
James Smart46fa3112007-04-25 09:51:45 -04001629
James Smart549e55c2007-08-02 11:09:51 -04001630 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001631 return;
James Smart688a8862006-07-06 15:49:56 -04001632
dea31012005-04-17 16:05:31 -05001633 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001634 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001635 vports = lpfc_create_vport_work_array(phba);
1636 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001637 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001638 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001639 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001640 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001641 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001642 /* Bring down the SLI Layer and cleanup. The HBA is offline
1643 now. */
1644 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001645 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001646 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001647 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -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 Smart549e55c2007-08-02 11:09:51 -04001651 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001652 spin_lock_irq(shost->host_lock);
1653 vports[i]->work_port_events = 0;
1654 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1655 spin_unlock_irq(shost->host_lock);
1656 }
James Smart09372822008-01-11 01:52:54 -05001657 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001658}
1659
1660/******************************************************************************
1661* Function name: lpfc_scsi_free
1662*
1663* Description: Called from lpfc_pci_remove_one free internal driver resources
1664*
1665******************************************************************************/
1666static int
James Smart2e0fef82007-06-17 19:56:36 -05001667lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001668{
1669 struct lpfc_scsi_buf *sb, *sb_next;
1670 struct lpfc_iocbq *io, *io_next;
1671
James Smart2e0fef82007-06-17 19:56:36 -05001672 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001673 /* Release all the lpfc_scsi_bufs maintained by this host. */
1674 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1675 list_del(&sb->list);
1676 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001677 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001678 kfree(sb);
1679 phba->total_scsi_bufs--;
1680 }
1681
1682 /* Release all the lpfc_iocbq entries maintained by this host. */
1683 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1684 list_del(&io->list);
1685 kfree(io);
1686 phba->total_iocbq_bufs--;
1687 }
1688
James Smart2e0fef82007-06-17 19:56:36 -05001689 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001690
1691 return 0;
1692}
1693
James Smart2e0fef82007-06-17 19:56:36 -05001694struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001695lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001696{
James Smart2e0fef82007-06-17 19:56:36 -05001697 struct lpfc_vport *vport;
1698 struct Scsi_Host *shost;
1699 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001700
James Smart3de2a652007-08-02 11:09:59 -04001701 if (dev != &phba->pcidev->dev)
1702 shost = scsi_host_alloc(&lpfc_vport_template,
1703 sizeof(struct lpfc_vport));
1704 else
1705 shost = scsi_host_alloc(&lpfc_template,
1706 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001707 if (!shost)
1708 goto out;
James Smart47a86172007-04-25 09:53:22 -04001709
James Smart2e0fef82007-06-17 19:56:36 -05001710 vport = (struct lpfc_vport *) shost->hostdata;
1711 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05001712 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001713 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05001714 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04001715
James Smart3de2a652007-08-02 11:09:59 -04001716 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001717 shost->unique_id = instance;
1718 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001719 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001720 shost->this_id = -1;
1721 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001722 /*
James Smart2e0fef82007-06-17 19:56:36 -05001723 * Set initial can_queue value since 0 is no longer supported and
1724 * scsi_add_host will fail. This will be adjusted later based on the
1725 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001726 */
James Smart2e0fef82007-06-17 19:56:36 -05001727 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001728 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001729 shost->transportt = lpfc_vport_transport_template;
1730 vport->port_type = LPFC_NPIV_PORT;
1731 } else {
1732 shost->transportt = lpfc_transport_template;
1733 vport->port_type = LPFC_PHYSICAL_PORT;
1734 }
James Smart47a86172007-04-25 09:53:22 -04001735
James Smart2e0fef82007-06-17 19:56:36 -05001736 /* Initialize all internally managed lists. */
1737 INIT_LIST_HEAD(&vport->fc_nodes);
1738 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001739
James Smart2e0fef82007-06-17 19:56:36 -05001740 init_timer(&vport->fc_disctmo);
1741 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001742 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001743
James Smart2e0fef82007-06-17 19:56:36 -05001744 init_timer(&vport->fc_fdmitmo);
1745 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001746 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001747
James Smart2e0fef82007-06-17 19:56:36 -05001748 init_timer(&vport->els_tmofunc);
1749 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001750 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001751
James Smart3de2a652007-08-02 11:09:59 -04001752 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001753 if (error)
1754 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001755
James Smart549e55c2007-08-02 11:09:51 -04001756 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001757 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001758 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001759 return vport;
James Smart47a86172007-04-25 09:53:22 -04001760
James Smart2e0fef82007-06-17 19:56:36 -05001761out_put_shost:
1762 scsi_host_put(shost);
1763out:
1764 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001765}
1766
James Smart2e0fef82007-06-17 19:56:36 -05001767void
1768destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001769{
James Smart92d7f7b2007-06-17 19:56:38 -05001770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1771 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001772
James Smart92d7f7b2007-06-17 19:56:38 -05001773 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001774
James Smart858c9f62007-06-17 19:56:39 -05001775 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001776 fc_remove_host(shost);
1777 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001778
James Smart92d7f7b2007-06-17 19:56:38 -05001779 spin_lock_irq(&phba->hbalock);
1780 list_del_init(&vport->listentry);
1781 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001782
James Smart92d7f7b2007-06-17 19:56:38 -05001783 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001784 return;
James Smart47a86172007-04-25 09:53:22 -04001785}
1786
James Smart92d7f7b2007-06-17 19:56:38 -05001787int
1788lpfc_get_instance(void)
1789{
1790 int instance = 0;
1791
1792 /* Assign an unused number */
1793 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1794 return -1;
1795 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1796 return -1;
1797 return instance;
1798}
1799
James Smart858c9f62007-06-17 19:56:39 -05001800/*
1801 * Note: there is no scan_start function as adapter initialization
1802 * will have asynchronously kicked off the link initialization.
1803 */
James Smart47a86172007-04-25 09:53:22 -04001804
1805int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1806{
James Smart2e0fef82007-06-17 19:56:36 -05001807 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1808 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001809 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001810
James Smart858c9f62007-06-17 19:56:39 -05001811 spin_lock_irq(shost->host_lock);
1812
James Smart51ef4c22007-08-02 11:10:31 -04001813 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05001814 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001815 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001816 }
James Smart2e0fef82007-06-17 19:56:36 -05001817 if (time >= 30 * HZ) {
1818 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001819 "0461 Scanning longer than 30 "
1820 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001821 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001822 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001823 }
1824 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1825 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001826 "0465 Link down longer than 15 "
1827 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001828 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001829 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001830 }
1831
James Smart2e0fef82007-06-17 19:56:36 -05001832 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001833 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001834 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001835 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001836 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001837 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001838 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001839 goto finished;
1840
1841 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001842
1843finished:
James Smart858c9f62007-06-17 19:56:39 -05001844 spin_unlock_irq(shost->host_lock);
1845 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001846}
1847
1848void lpfc_host_attrib_init(struct Scsi_Host *shost)
1849{
1850 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1851 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001852 /*
James Smart2e0fef82007-06-17 19:56:36 -05001853 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001854 */
1855
James Smart2e0fef82007-06-17 19:56:36 -05001856 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1857 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001858 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1859
1860 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001861 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001862 fc_host_supported_fc4s(shost)[2] = 1;
1863 fc_host_supported_fc4s(shost)[7] = 1;
1864
James Smart92d7f7b2007-06-17 19:56:38 -05001865 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1866 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001867
1868 fc_host_supported_speeds(shost) = 0;
1869 if (phba->lmt & LMT_10Gb)
1870 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04001871 if (phba->lmt & LMT_8Gb)
1872 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04001873 if (phba->lmt & LMT_4Gb)
1874 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1875 if (phba->lmt & LMT_2Gb)
1876 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1877 if (phba->lmt & LMT_1Gb)
1878 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1879
1880 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001881 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1882 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001883
1884 /* This value is also unchanging */
1885 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001886 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001887 fc_host_active_fc4s(shost)[2] = 1;
1888 fc_host_active_fc4s(shost)[7] = 1;
1889
James Smart92d7f7b2007-06-17 19:56:38 -05001890 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001891 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001892 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001893 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001894}
dea31012005-04-17 16:05:31 -05001895
James Smartdb2378e2008-02-08 18:49:51 -05001896static int
1897lpfc_enable_msix(struct lpfc_hba *phba)
1898{
1899 int error;
1900
1901 phba->msix_entries[0].entry = 0;
1902 phba->msix_entries[0].vector = 0;
1903
1904 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
1905 ARRAY_SIZE(phba->msix_entries));
1906 if (error) {
1907 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1908 "0420 Enable MSI-X failed (%d), continuing "
1909 "with MSI\n", error);
1910 pci_disable_msix(phba->pcidev);
1911 return error;
1912 }
1913
1914 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
1915 LPFC_DRIVER_NAME, phba);
1916 if (error) {
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "0421 MSI-X request_irq failed (%d), "
1919 "continuing with MSI\n", error);
1920 pci_disable_msix(phba->pcidev);
1921 }
1922 return error;
1923}
1924
1925static void
1926lpfc_disable_msix(struct lpfc_hba *phba)
1927{
1928 free_irq(phba->msix_entries[0].vector, phba);
1929 pci_disable_msix(phba->pcidev);
1930}
1931
dea31012005-04-17 16:05:31 -05001932static int __devinit
1933lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1934{
James Smart2e0fef82007-06-17 19:56:36 -05001935 struct lpfc_vport *vport = NULL;
1936 struct lpfc_hba *phba;
1937 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001938 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001939 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04001940 void *ptr;
dea31012005-04-17 16:05:31 -05001941 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04001942 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04001943 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05001944 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001945 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05001946
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01001947 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05001948 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001949 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05001950 goto out_disable_device;
1951
James Smart2e0fef82007-06-17 19:56:36 -05001952 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1953 if (!phba)
dea31012005-04-17 16:05:31 -05001954 goto out_release_regions;
1955
James Smart2e0fef82007-06-17 19:56:36 -05001956 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001957
James Smarte47c9092008-02-08 18:49:26 -05001958 /* Initialize ndlp management spinlock */
1959 spin_lock_init(&phba->ndlp_lock);
1960
dea31012005-04-17 16:05:31 -05001961 phba->pcidev = pdev;
1962
1963 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001964 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001965 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001966
James Smart2e0fef82007-06-17 19:56:36 -05001967 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05001968 /*
1969 * Get all the module params for configuring this host and then
1970 * establish the host.
1971 */
1972 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001973 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05001974
1975 /* Initialize timers used by driver */
James Smart858c9f62007-06-17 19:56:39 -05001976 init_timer(&phba->hb_tmofunc);
1977 phba->hb_tmofunc.function = lpfc_hb_timeout;
1978 phba->hb_tmofunc.data = (unsigned long)phba;
1979
dea31012005-04-17 16:05:31 -05001980 psli = &phba->sli;
1981 init_timer(&psli->mbox_tmo);
1982 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001983 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001984 init_timer(&phba->fcp_poll_timer);
1985 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001986 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001987 init_timer(&phba->fabric_block_timer);
1988 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1989 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001990
dea31012005-04-17 16:05:31 -05001991 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07001992 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05001993
1994 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1995 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1996 goto out_idr_remove;
1997
1998 /*
1999 * Get the bus address of Bar0 and Bar2 and the number of bytes
2000 * required by each mapping.
2001 */
2002 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2003 bar0map_len = pci_resource_len(phba->pcidev, 0);
2004
2005 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2006 bar2map_len = pci_resource_len(phba->pcidev, 2);
2007
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002008 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002009 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002010 if (!phba->slim_memmap_p) {
2011 error = -ENODEV;
2012 dev_printk(KERN_ERR, &pdev->dev,
2013 "ioremap failed for SLIM memory.\n");
2014 goto out_idr_remove;
2015 }
2016
2017 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002018 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002019 if (!phba->ctrl_regs_memmap_p) {
2020 error = -ENODEV;
2021 dev_printk(KERN_ERR, &pdev->dev,
2022 "ioremap failed for HBA control registers.\n");
2023 goto out_iounmap_slim;
2024 }
dea31012005-04-17 16:05:31 -05002025
2026 /* Allocate memory for SLI-2 structures */
2027 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
2028 &phba->slim2p_mapping, GFP_KERNEL);
2029 if (!phba->slim2p)
2030 goto out_iounmap;
2031
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04002032 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05002033
James Smarted957682007-06-17 19:56:37 -05002034 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2035 lpfc_sli_hbq_size(),
2036 &phba->hbqslimp.phys,
2037 GFP_KERNEL);
2038 if (!phba->hbqslimp.virt)
2039 goto out_free_slim;
2040
James Smart51ef4c22007-08-02 11:10:31 -04002041 hbq_count = lpfc_sli_hbq_count();
2042 ptr = phba->hbqslimp.virt;
2043 for (i = 0; i < hbq_count; ++i) {
2044 phba->hbqs[i].hbq_virt = ptr;
2045 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2046 ptr += (lpfc_hbq_defs[i]->entry_count *
2047 sizeof(struct lpfc_hbq_entry));
2048 }
2049 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2050 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2051
James Smarted957682007-06-17 19:56:37 -05002052 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2053
James Smart3163f722008-02-08 18:50:25 -05002054 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2055
dea31012005-04-17 16:05:31 -05002056 /* Initialize the SLI Layer to run with lpfc HBAs. */
2057 lpfc_sli_setup(phba);
2058 lpfc_sli_queue_setup(phba);
2059
James Smart98c9ea52007-10-27 13:37:33 -04002060 retval = lpfc_mem_alloc(phba);
2061 if (retval) {
2062 error = retval;
James Smarted957682007-06-17 19:56:37 -05002063 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002064 }
dea31012005-04-17 16:05:31 -05002065
2066 /* Initialize and populate the iocb list per host. */
2067 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2068 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002069 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002070 if (iocbq_entry == NULL) {
2071 printk(KERN_ERR "%s: only allocated %d iocbs of "
2072 "expected %d count. Unloading driver.\n",
2073 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
2074 error = -ENOMEM;
2075 goto out_free_iocbq;
2076 }
2077
James Bottomley604a3e32005-10-29 10:28:33 -05002078 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2079 if (iotag == 0) {
2080 kfree (iocbq_entry);
2081 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2082 "Unloading driver.\n",
2083 __FUNCTION__);
2084 error = -ENOMEM;
2085 goto out_free_iocbq;
2086 }
James Smart2e0fef82007-06-17 19:56:36 -05002087
2088 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002089 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2090 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002091 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002092 }
2093
2094 /* Initialize HBA structure */
2095 phba->fc_edtov = FF_DEF_EDTOV;
2096 phba->fc_ratov = FF_DEF_RATOV;
2097 phba->fc_altov = FF_DEF_ALTOV;
2098 phba->fc_arbtov = FF_DEF_ARBTOV;
2099
2100 INIT_LIST_HEAD(&phba->work_list);
2101 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2102 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2103
2104 /* Startup the kernel thread for this host adapter. */
2105 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2106 "lpfc_worker_%d", phba->brd_no);
2107 if (IS_ERR(phba->worker_thread)) {
2108 error = PTR_ERR(phba->worker_thread);
2109 goto out_free_iocbq;
2110 }
2111
dea31012005-04-17 16:05:31 -05002112 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002113 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002114 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2115
James Smart92d7f7b2007-06-17 19:56:38 -05002116 /* Initialize list of fabric iocbs */
2117 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2118
James Smart0ff10d42008-01-11 01:52:36 -05002119 /* Initialize list to save ELS buffers */
2120 INIT_LIST_HEAD(&phba->elsbuf);
2121
James Smart3de2a652007-08-02 11:09:59 -04002122 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002123 if (!vport)
2124 goto out_kthread_stop;
2125
2126 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002127 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002128 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002129
James Smart92d7f7b2007-06-17 19:56:38 -05002130 pci_set_drvdata(pdev, shost);
James Smartdb2378e2008-02-08 18:49:51 -05002131 phba->intr_type = NONE;
dea31012005-04-17 16:05:31 -05002132
James Smartdb2378e2008-02-08 18:49:51 -05002133 if (phba->cfg_use_msi == 2) {
2134 error = lpfc_enable_msix(phba);
2135 if (!error)
2136 phba->intr_type = MSIX;
2137 }
2138
2139 /* Fallback to MSI if MSI-X initialization failed */
2140 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
James Smart98c9ea52007-10-27 13:37:33 -04002141 retval = pci_enable_msi(phba->pcidev);
2142 if (!retval)
James Smartdb2378e2008-02-08 18:49:51 -05002143 phba->intr_type = MSI;
James Smart51ef4c22007-08-02 11:10:31 -04002144 else
James Smarte8b62012007-08-02 11:10:09 -04002145 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2146 "0452 Enable MSI failed, continuing "
2147 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002148 }
2149
James Smartdb2378e2008-02-08 18:49:51 -05002150 /* MSI-X is the only case the doesn't need to call request_irq */
2151 if (phba->intr_type != MSIX) {
2152 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2153 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2154 if (retval) {
2155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2156 "interrupt handler failed\n");
2157 error = retval;
2158 goto out_disable_msi;
2159 } else if (phba->intr_type != MSI)
2160 phba->intr_type = INTx;
dea31012005-04-17 16:05:31 -05002161 }
dea31012005-04-17 16:05:31 -05002162
James Smart2e0fef82007-06-17 19:56:36 -05002163 phba->MBslimaddr = phba->slim_memmap_p;
2164 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2165 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2166 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2167 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2168
James Smart98c9ea52007-10-27 13:37:33 -04002169 if (lpfc_alloc_sysfs_attr(vport)) {
2170 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002171 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002172 }
dea31012005-04-17 16:05:31 -05002173
James Smart98c9ea52007-10-27 13:37:33 -04002174 if (lpfc_sli_hba_setup(phba)) {
2175 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002176 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002177 }
James Smart858c9f62007-06-17 19:56:39 -05002178
2179 /*
2180 * hba setup may have changed the hba_queue_depth so we need to adjust
2181 * the value of can_queue.
2182 */
2183 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2184
2185 lpfc_host_attrib_init(shost);
2186
James Smart2e0fef82007-06-17 19:56:36 -05002187 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2188 spin_lock_irq(shost->host_lock);
2189 lpfc_poll_start_timer(phba);
2190 spin_unlock_irq(shost->host_lock);
2191 }
James Smart8f6d98d2006-08-01 07:34:00 -04002192
James Smart858c9f62007-06-17 19:56:39 -05002193 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002194
dea31012005-04-17 16:05:31 -05002195 return 0;
2196
James Smart858c9f62007-06-17 19:56:39 -05002197out_remove_device:
2198 lpfc_free_sysfs_attr(vport);
2199 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002200 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002201 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002202out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002203 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002204 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002205
2206 if (phba->intr_type == MSIX)
2207 lpfc_disable_msix(phba);
2208 else
2209 free_irq(phba->pcidev->irq, phba);
2210
James Smart92d7f7b2007-06-17 19:56:38 -05002211out_disable_msi:
James Smartdb2378e2008-02-08 18:49:51 -05002212 if (phba->intr_type == MSI)
James Smart51ef4c22007-08-02 11:10:31 -04002213 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002214 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002215out_kthread_stop:
2216 kthread_stop(phba->worker_thread);
2217out_free_iocbq:
2218 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2219 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002220 kfree(iocbq_entry);
2221 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002222 }
2223 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002224out_free_hbqslimp:
2225 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2226 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002227out_free_slim:
2228 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2229 phba->slim2p_mapping);
2230out_iounmap:
2231 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002232out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002233 iounmap(phba->slim_memmap_p);
2234out_idr_remove:
2235 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002236out_free_phba:
2237 kfree(phba);
dea31012005-04-17 16:05:31 -05002238out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002239 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002240out_disable_device:
2241 pci_disable_device(pdev);
2242out:
James Smartdefbcf12006-04-16 22:26:50 -04002243 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002244 if (shost)
2245 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002246 return error;
2247}
2248
2249static void __devexit
2250lpfc_pci_remove_one(struct pci_dev *pdev)
2251{
James Smart2e0fef82007-06-17 19:56:36 -05002252 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2253 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2254 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002255 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2256
James Smart549e55c2007-08-02 11:09:51 -04002257 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002258 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002259 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002260
James Smart858c9f62007-06-17 19:56:39 -05002261 kfree(vport->vname);
2262 lpfc_free_sysfs_attr(vport);
2263
James Smart09372822008-01-11 01:52:54 -05002264 kthread_stop(phba->worker_thread);
2265
James Smart858c9f62007-06-17 19:56:39 -05002266 fc_remove_host(shost);
2267 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002268 lpfc_cleanup(vport);
2269
James Smart2e0fef82007-06-17 19:56:36 -05002270 /*
2271 * Bring down the SLI Layer. This step disable all interrupts,
2272 * clears the rings, discards all mailbox commands, and resets
2273 * the HBA.
2274 */
2275 lpfc_sli_hba_down(phba);
2276 lpfc_sli_brdrestart(phba);
2277
James Smart92d7f7b2007-06-17 19:56:38 -05002278 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002279 spin_lock_irq(&phba->hbalock);
2280 list_del_init(&vport->listentry);
2281 spin_unlock_irq(&phba->hbalock);
2282
James Smart858c9f62007-06-17 19:56:39 -05002283 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002284
James Smartdb2378e2008-02-08 18:49:51 -05002285 if (phba->intr_type == MSIX)
2286 lpfc_disable_msix(phba);
2287 else {
2288 free_irq(phba->pcidev->irq, phba);
2289 if (phba->intr_type == MSI)
2290 pci_disable_msi(phba->pcidev);
2291 }
dea31012005-04-17 16:05:31 -05002292
2293 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002294 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002295
2296 /*
2297 * Call scsi_free before mem_free since scsi bufs are released to their
2298 * corresponding pools here.
2299 */
2300 lpfc_scsi_free(phba);
2301 lpfc_mem_free(phba);
2302
James Smarted957682007-06-17 19:56:37 -05002303 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2304 phba->hbqslimp.phys);
2305
James Smart2e0fef82007-06-17 19:56:36 -05002306 /* Free resources associated with SLI2 interface */
2307 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2308 phba->slim2p, phba->slim2p_mapping);
2309
2310 /* unmap adapter SLIM and Control Registers */
2311 iounmap(phba->ctrl_regs_memmap_p);
2312 iounmap(phba->slim_memmap_p);
2313
2314 idr_remove(&lpfc_hba_index, phba->brd_no);
2315
2316 kfree(phba);
2317
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002318 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002319 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002320}
2321
Linas Vepstas8d63f372007-02-14 14:28:36 -06002322/**
2323 * lpfc_io_error_detected - called when PCI error is detected
2324 * @pdev: Pointer to PCI device
2325 * @state: The current pci conneection state
2326 *
2327 * This function is called after a PCI bus error affecting
2328 * this device has been detected.
2329 */
2330static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2331 pci_channel_state_t state)
2332{
James Smart51ef4c22007-08-02 11:10:31 -04002333 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2334 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002335 struct lpfc_sli *psli = &phba->sli;
2336 struct lpfc_sli_ring *pring;
2337
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002338 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002339 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002340
Linas Vepstas8d63f372007-02-14 14:28:36 -06002341 pci_disable_device(pdev);
2342 /*
2343 * There may be I/Os dropped by the firmware.
2344 * Error iocb (I/O) on txcmplq and let the SCSI layer
2345 * retry it after re-establishing link.
2346 */
2347 pring = &psli->ring[psli->fcp_ring];
2348 lpfc_sli_abort_iocb_ring(phba, pring);
2349
James Smartdb2378e2008-02-08 18:49:51 -05002350 if (phba->intr_type == MSIX)
2351 lpfc_disable_msix(phba);
2352 else {
2353 free_irq(phba->pcidev->irq, phba);
2354 if (phba->intr_type == MSI)
2355 pci_disable_msi(phba->pcidev);
2356 }
James Smart51ef4c22007-08-02 11:10:31 -04002357
Linas Vepstas8d63f372007-02-14 14:28:36 -06002358 /* Request a slot reset. */
2359 return PCI_ERS_RESULT_NEED_RESET;
2360}
2361
2362/**
2363 * lpfc_io_slot_reset - called after the pci bus has been reset.
2364 * @pdev: Pointer to PCI device
2365 *
2366 * Restart the card from scratch, as if from a cold-boot.
2367 */
2368static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2369{
James Smart51ef4c22007-08-02 11:10:31 -04002370 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2371 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002372 struct lpfc_sli *psli = &phba->sli;
James Smart9b379602008-04-07 10:16:00 -04002373 int error, retval;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002374
2375 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002376 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002377 printk(KERN_ERR "lpfc: Cannot re-enable "
2378 "PCI device after reset.\n");
2379 return PCI_ERS_RESULT_DISCONNECT;
2380 }
2381
2382 pci_set_master(pdev);
2383
James Smart92d7f7b2007-06-17 19:56:38 -05002384 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002385 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002386 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002387
James Smart9b379602008-04-07 10:16:00 -04002388 /* Enable configured interrupt method */
2389 phba->intr_type = NONE;
2390 if (phba->cfg_use_msi == 2) {
2391 error = lpfc_enable_msix(phba);
2392 if (!error)
2393 phba->intr_type = MSIX;
2394 }
2395
2396 /* Fallback to MSI if MSI-X initialization failed */
2397 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2398 retval = pci_enable_msi(phba->pcidev);
2399 if (!retval)
2400 phba->intr_type = MSI;
2401 else
2402 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2403 "0470 Enable MSI failed, continuing "
2404 "with IRQ\n");
2405 }
2406
2407 /* MSI-X is the only case the doesn't need to call request_irq */
2408 if (phba->intr_type != MSIX) {
2409 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2410 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2411 if (retval) {
2412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2413 "0471 Enable interrupt handler "
2414 "failed\n");
2415 } else if (phba->intr_type != MSI)
2416 phba->intr_type = INTx;
2417 }
Linas Vepstas8d63f372007-02-14 14:28:36 -06002418
2419 /* Take device offline; this will perform cleanup */
2420 lpfc_offline(phba);
2421 lpfc_sli_brdrestart(phba);
2422
2423 return PCI_ERS_RESULT_RECOVERED;
2424}
2425
2426/**
2427 * lpfc_io_resume - called when traffic can start flowing again.
2428 * @pdev: Pointer to PCI device
2429 *
2430 * This callback is called when the error recovery driver tells us that
2431 * its OK to resume normal operation.
2432 */
2433static void lpfc_io_resume(struct pci_dev *pdev)
2434{
James Smart51ef4c22007-08-02 11:10:31 -04002435 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2436 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002437
James Smart58da1ff2008-04-07 10:15:56 -04002438 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002439}
2440
dea31012005-04-17 16:05:31 -05002441static struct pci_device_id lpfc_id_table[] = {
2442 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2443 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002444 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2445 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002446 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2447 PCI_ANY_ID, PCI_ANY_ID, },
2448 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2449 PCI_ANY_ID, PCI_ANY_ID, },
2450 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2451 PCI_ANY_ID, PCI_ANY_ID, },
2452 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2453 PCI_ANY_ID, PCI_ANY_ID, },
2454 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2455 PCI_ANY_ID, PCI_ANY_ID, },
2456 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2457 PCI_ANY_ID, PCI_ANY_ID, },
2458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2459 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2461 PCI_ANY_ID, PCI_ANY_ID, },
2462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2463 PCI_ANY_ID, PCI_ANY_ID, },
2464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2465 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2467 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2469 PCI_ANY_ID, PCI_ANY_ID, },
2470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2471 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2473 PCI_ANY_ID, PCI_ANY_ID, },
2474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2475 PCI_ANY_ID, PCI_ANY_ID, },
2476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2477 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2479 PCI_ANY_ID, PCI_ANY_ID, },
2480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2481 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2483 PCI_ANY_ID, PCI_ANY_ID, },
2484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2485 PCI_ANY_ID, PCI_ANY_ID, },
2486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2487 PCI_ANY_ID, PCI_ANY_ID, },
2488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2489 PCI_ANY_ID, PCI_ANY_ID, },
2490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2491 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2493 PCI_ANY_ID, PCI_ANY_ID, },
2494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2495 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2497 PCI_ANY_ID, PCI_ANY_ID, },
2498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2499 PCI_ANY_ID, PCI_ANY_ID, },
2500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2501 PCI_ANY_ID, PCI_ANY_ID, },
2502 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2503 PCI_ANY_ID, PCI_ANY_ID, },
2504 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2505 PCI_ANY_ID, PCI_ANY_ID, },
2506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2507 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002508 { 0 }
2509};
2510
2511MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2512
Linas Vepstas8d63f372007-02-14 14:28:36 -06002513static struct pci_error_handlers lpfc_err_handler = {
2514 .error_detected = lpfc_io_error_detected,
2515 .slot_reset = lpfc_io_slot_reset,
2516 .resume = lpfc_io_resume,
2517};
2518
dea31012005-04-17 16:05:31 -05002519static struct pci_driver lpfc_driver = {
2520 .name = LPFC_DRIVER_NAME,
2521 .id_table = lpfc_id_table,
2522 .probe = lpfc_pci_probe_one,
2523 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002524 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002525};
2526
2527static int __init
2528lpfc_init(void)
2529{
2530 int error = 0;
2531
2532 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002533 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002534
James Smart7ee5d432007-10-27 13:37:17 -04002535 if (lpfc_enable_npiv) {
2536 lpfc_transport_functions.vport_create = lpfc_vport_create;
2537 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2538 }
dea31012005-04-17 16:05:31 -05002539 lpfc_transport_template =
2540 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002541 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002542 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002543 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002544 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002545 fc_attach_transport(&lpfc_vport_transport_functions);
2546 if (lpfc_vport_transport_template == NULL) {
2547 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002548 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002549 }
James Smart7ee5d432007-10-27 13:37:17 -04002550 }
dea31012005-04-17 16:05:31 -05002551 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002552 if (error) {
dea31012005-04-17 16:05:31 -05002553 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002554 fc_release_transport(lpfc_vport_transport_template);
2555 }
dea31012005-04-17 16:05:31 -05002556
2557 return error;
2558}
2559
2560static void __exit
2561lpfc_exit(void)
2562{
2563 pci_unregister_driver(&lpfc_driver);
2564 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002565 if (lpfc_enable_npiv)
2566 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002567}
2568
2569module_init(lpfc_init);
2570module_exit(lpfc_exit);
2571MODULE_LICENSE("GPL");
2572MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2573MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2574MODULE_VERSION("0:" LPFC_DRIVER_VERSION);