blob: 22843751c2caf1897bd240d514d5e85e3abf0d0d [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
562 if (phba->work_wait)
563 wake_up(phba->work_wait);
564 return;
565}
566
567static void
568lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
569{
570 unsigned long drvr_flag;
571
572 spin_lock_irqsave(&phba->hbalock, drvr_flag);
573 phba->hb_outstanding = 0;
574 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
575
576 mempool_free(pmboxq, phba->mbox_mem_pool);
577 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
578 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400579 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500580 mod_timer(&phba->hb_tmofunc,
581 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
582 return;
583}
584
585void
586lpfc_hb_timeout_handler(struct lpfc_hba *phba)
587{
588 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500589 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500590 int retval;
591 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500592 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500593
594 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400595 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500596 (phba->pport->fc_flag & FC_OFFLINE_MODE))
597 return;
598
599 spin_lock_irq(&phba->pport->work_port_lock);
600 /* If the timer is already canceled do nothing */
601 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
602 spin_unlock_irq(&phba->pport->work_port_lock);
603 return;
604 }
605
606 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
607 jiffies)) {
608 spin_unlock_irq(&phba->pport->work_port_lock);
609 if (!phba->hb_outstanding)
610 mod_timer(&phba->hb_tmofunc,
611 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
612 else
613 mod_timer(&phba->hb_tmofunc,
614 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
615 return;
616 }
617 spin_unlock_irq(&phba->pport->work_port_lock);
618
James Smart0ff10d42008-01-11 01:52:36 -0500619 if (phba->elsbuf_cnt &&
620 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
621 spin_lock_irq(&phba->hbalock);
622 list_splice_init(&phba->elsbuf, &completions);
623 phba->elsbuf_cnt = 0;
624 phba->elsbuf_prev_cnt = 0;
625 spin_unlock_irq(&phba->hbalock);
626
627 while (!list_empty(&completions)) {
628 list_remove_head(&completions, buf_ptr,
629 struct lpfc_dmabuf, list);
630 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
631 kfree(buf_ptr);
632 }
633 }
634 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
635
James Smart858c9f62007-06-17 19:56:39 -0500636 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500637 if (phba->cfg_enable_hba_heartbeat) {
638 if (!phba->hb_outstanding) {
639 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
640 if (!pmboxq) {
641 mod_timer(&phba->hb_tmofunc,
642 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
643 return;
644 }
645
646 lpfc_heart_beat(phba, pmboxq);
647 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
648 pmboxq->vport = phba->pport;
649 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
650
651 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
652 mempool_free(pmboxq, phba->mbox_mem_pool);
653 mod_timer(&phba->hb_tmofunc,
654 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
655 return;
656 }
James Smart858c9f62007-06-17 19:56:39 -0500657 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500658 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
659 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500660 return;
James Smart13815c82008-01-11 01:52:48 -0500661 } else {
662 /*
663 * If heart beat timeout called with hb_outstanding set
664 * we need to take the HBA offline.
665 */
666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
667 "0459 Adapter heartbeat failure, "
668 "taking this port offline.\n");
669
670 spin_lock_irq(&phba->hbalock);
671 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
672 spin_unlock_irq(&phba->hbalock);
673
674 lpfc_offline_prep(phba);
675 lpfc_offline(phba);
676 lpfc_unblock_mgmt_io(phba);
677 phba->link_state = LPFC_HBA_ERROR;
678 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500679 }
James Smart858c9f62007-06-17 19:56:39 -0500680 }
681}
682
James Smart09372822008-01-11 01:52:54 -0500683static void
684lpfc_offline_eratt(struct lpfc_hba *phba)
685{
686 struct lpfc_sli *psli = &phba->sli;
687
688 spin_lock_irq(&phba->hbalock);
689 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
690 spin_unlock_irq(&phba->hbalock);
691 lpfc_offline_prep(phba);
692
693 lpfc_offline(phba);
694 lpfc_reset_barrier(phba);
695 lpfc_sli_brdreset(phba);
696 lpfc_hba_down_post(phba);
697 lpfc_sli_brdready(phba, HS_MBRDY);
698 lpfc_unblock_mgmt_io(phba);
699 phba->link_state = LPFC_HBA_ERROR;
700 return;
701}
702
Jamie Wellnitz41415862006-02-28 19:25:27 -0500703/************************************************************************/
704/* */
dea31012005-04-17 16:05:31 -0500705/* lpfc_handle_eratt */
706/* This routine will handle processing a Host Attention */
707/* Error Status event. This will be initialized */
708/* as a SLI layer callback routine. */
709/* */
710/************************************************************************/
711void
James Smart2e0fef82007-06-17 19:56:36 -0500712lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500713{
James Smart2e0fef82007-06-17 19:56:36 -0500714 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500715 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500716 struct lpfc_sli_ring *pring;
James Smart549e55c2007-08-02 11:09:51 -0400717 struct lpfc_vport **vports;
James Smartd2873e42006-08-18 17:46:43 -0400718 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400719 unsigned long temperature;
720 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500721 struct Scsi_Host *shost;
James Smart549e55c2007-08-02 11:09:51 -0400722 int i;
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 Smartf5603512006-12-02 13:35:43 -0500732 if (phba->work_hs & HS_FFER6 ||
733 phba->work_hs & HS_FFER5) {
dea31012005-04-17 16:05:31 -0500734 /* Re-establishing Link */
735 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400736 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500737 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400738 phba->work_hs,
dea31012005-04-17 16:05:31 -0500739 phba->work_status[0], phba->work_status[1]);
James Smart549e55c2007-08-02 11:09:51 -0400740 vports = lpfc_create_vport_work_array(phba);
741 if (vports != NULL)
742 for(i = 0;
James Smart09372822008-01-11 01:52:54 -0500743 i <= phba->max_vpi && vports[i] != NULL;
James Smart549e55c2007-08-02 11:09:51 -0400744 i++){
745 shost = lpfc_shost_from_vport(vports[i]);
746 spin_lock_irq(shost->host_lock);
747 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
748 spin_unlock_irq(shost->host_lock);
749 }
James Smart09372822008-01-11 01:52:54 -0500750 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500751 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500752 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500753 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500754
755 /*
756 * Firmware stops when it triggled erratt with HS_FFER6.
757 * That could cause the I/Os dropped by the firmware.
758 * Error iocb (I/O) on txcmplq and let the SCSI layer
759 * retry it after re-establishing link.
760 */
761 pring = &psli->ring[psli->fcp_ring];
762 lpfc_sli_abort_iocb_ring(phba, pring);
763
764
765 /*
766 * There was a firmware error. Take the hba offline and then
767 * attempt to restart it.
768 */
James Smart46fa3112007-04-25 09:51:45 -0400769 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500770 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500771 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500772 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
773 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
James Smart46fa3112007-04-25 09:51:45 -0400774 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500775 return;
776 }
James Smart46fa3112007-04-25 09:51:45 -0400777 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400778 } else if (phba->work_hs & HS_CRIT_TEMP) {
779 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
780 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
781 temp_event_data.event_code = LPFC_CRIT_TEMP;
782 temp_event_data.data = (uint32_t)temperature;
783
784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
785 "0459 Adapter maximum temperature exceeded "
786 "(%ld), taking this port offline "
787 "Data: x%x x%x x%x\n",
788 temperature, phba->work_hs,
789 phba->work_status[0], phba->work_status[1]);
790
791 shost = lpfc_shost_from_vport(phba->pport);
792 fc_host_post_vendor_event(shost, fc_get_event_number(),
793 sizeof(temp_event_data),
794 (char *) &temp_event_data,
795 SCSI_NL_VID_TYPE_PCI
796 | PCI_VENDOR_ID_EMULEX);
797
James Smart7af67052007-10-27 13:38:11 -0400798 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400799 phba->over_temp_state = HBA_OVER_TEMP;
800 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500801 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400802
dea31012005-04-17 16:05:31 -0500803 } else {
804 /* The if clause above forces this code path when the status
805 * failure is a value other than FFER6. Do not call the offline
806 * twice. This is the adapter hardware error path.
807 */
808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400809 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500810 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400811 phba->work_hs,
dea31012005-04-17 16:05:31 -0500812 phba->work_status[0], phba->work_status[1]);
813
James Smartd2873e42006-08-18 17:46:43 -0400814 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500815 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500816 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400817 sizeof(event_data), (char *) &event_data,
818 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
819
James Smart09372822008-01-11 01:52:54 -0500820 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500821 }
822}
823
824/************************************************************************/
825/* */
826/* lpfc_handle_latt */
827/* This routine will handle processing a Host Attention */
828/* Link Status event. This will be initialized */
829/* as a SLI layer callback routine. */
830/* */
831/************************************************************************/
832void
James Smart2e0fef82007-06-17 19:56:36 -0500833lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500834{
James Smart2e0fef82007-06-17 19:56:36 -0500835 struct lpfc_vport *vport = phba->pport;
836 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500837 LPFC_MBOXQ_t *pmb;
838 volatile uint32_t control;
839 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500840 int rc = 0;
dea31012005-04-17 16:05:31 -0500841
842 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500843 if (!pmb) {
844 rc = 1;
dea31012005-04-17 16:05:31 -0500845 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500846 }
dea31012005-04-17 16:05:31 -0500847
848 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500849 if (!mp) {
850 rc = 2;
dea31012005-04-17 16:05:31 -0500851 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500852 }
dea31012005-04-17 16:05:31 -0500853
854 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500855 if (!mp->virt) {
856 rc = 3;
dea31012005-04-17 16:05:31 -0500857 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500858 }
dea31012005-04-17 16:05:31 -0500859
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500860 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400861 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500862
863 psli->slistat.link_event++;
864 lpfc_read_la(phba, pmb, mp);
865 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500866 pmb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400867 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500868 if (rc == MBX_NOT_FINISHED) {
869 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500870 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500871 }
dea31012005-04-17 16:05:31 -0500872
873 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500874 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500875 writel(HA_LATT, phba->HAregaddr);
876 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500877 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500878
879 return;
880
James Smart14691152006-12-02 13:34:28 -0500881lpfc_handle_latt_free_mbuf:
882 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500883lpfc_handle_latt_free_mp:
884 kfree(mp);
885lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400886 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500887lpfc_handle_latt_err_exit:
888 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500889 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500890 psli->sli_flag |= LPFC_PROCESS_LA;
891 control = readl(phba->HCregaddr);
892 control |= HC_LAINT_ENA;
893 writel(control, phba->HCregaddr);
894 readl(phba->HCregaddr); /* flush */
895
896 /* Clear Link Attention in HA REG */
897 writel(HA_LATT, phba->HAregaddr);
898 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500899 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500900 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500901 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500902
James Smart09372822008-01-11 01:52:54 -0500903 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
904 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500905
906 return;
907}
908
909/************************************************************************/
910/* */
911/* lpfc_parse_vpd */
912/* This routine will parse the VPD data */
913/* */
914/************************************************************************/
915static int
James Smart2e0fef82007-06-17 19:56:36 -0500916lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500917{
918 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500919 int Length;
dea31012005-04-17 16:05:31 -0500920 int i, j;
921 int finished = 0;
922 int index = 0;
923
924 if (!vpd)
925 return 0;
926
927 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500928 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400929 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500930 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
931 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500932 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500933 switch (vpd[index]) {
934 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500935 case 0x91:
dea31012005-04-17 16:05:31 -0500936 index += 1;
937 lenlo = vpd[index];
938 index += 1;
939 lenhi = vpd[index];
940 index += 1;
941 i = ((((unsigned short)lenhi) << 8) + lenlo);
942 index += i;
943 break;
944 case 0x90:
945 index += 1;
946 lenlo = vpd[index];
947 index += 1;
948 lenhi = vpd[index];
949 index += 1;
950 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500951 if (Length > len - index)
952 Length = len - index;
dea31012005-04-17 16:05:31 -0500953 while (Length > 0) {
954 /* Look for Serial Number */
955 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
956 index += 2;
957 i = vpd[index];
958 index += 1;
959 j = 0;
960 Length -= (3+i);
961 while(i--) {
962 phba->SerialNumber[j++] = vpd[index++];
963 if (j == 31)
964 break;
965 }
966 phba->SerialNumber[j] = 0;
967 continue;
968 }
969 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
970 phba->vpd_flag |= VPD_MODEL_DESC;
971 index += 2;
972 i = vpd[index];
973 index += 1;
974 j = 0;
975 Length -= (3+i);
976 while(i--) {
977 phba->ModelDesc[j++] = vpd[index++];
978 if (j == 255)
979 break;
980 }
981 phba->ModelDesc[j] = 0;
982 continue;
983 }
984 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
985 phba->vpd_flag |= VPD_MODEL_NAME;
986 index += 2;
987 i = vpd[index];
988 index += 1;
989 j = 0;
990 Length -= (3+i);
991 while(i--) {
992 phba->ModelName[j++] = vpd[index++];
993 if (j == 79)
994 break;
995 }
996 phba->ModelName[j] = 0;
997 continue;
998 }
999 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1000 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1001 index += 2;
1002 i = vpd[index];
1003 index += 1;
1004 j = 0;
1005 Length -= (3+i);
1006 while(i--) {
1007 phba->ProgramType[j++] = vpd[index++];
1008 if (j == 255)
1009 break;
1010 }
1011 phba->ProgramType[j] = 0;
1012 continue;
1013 }
1014 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1015 phba->vpd_flag |= VPD_PORT;
1016 index += 2;
1017 i = vpd[index];
1018 index += 1;
1019 j = 0;
1020 Length -= (3+i);
1021 while(i--) {
1022 phba->Port[j++] = vpd[index++];
1023 if (j == 19)
1024 break;
1025 }
1026 phba->Port[j] = 0;
1027 continue;
1028 }
1029 else {
1030 index += 2;
1031 i = vpd[index];
1032 index += 1;
1033 index += i;
1034 Length -= (3 + i);
1035 }
1036 }
1037 finished = 0;
1038 break;
1039 case 0x78:
1040 finished = 1;
1041 break;
1042 default:
1043 index ++;
1044 break;
1045 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001046 }
dea31012005-04-17 16:05:31 -05001047
1048 return(1);
1049}
1050
1051static void
James Smart2e0fef82007-06-17 19:56:36 -05001052lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001053{
1054 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001055 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001056 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001057 struct {
1058 char * name;
1059 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001060 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001061 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001062
1063 if (mdp && mdp[0] != '\0'
1064 && descp && descp[0] != '\0')
1065 return;
1066
1067 if (phba->lmt & LMT_10Gb)
1068 max_speed = 10;
1069 else if (phba->lmt & LMT_8Gb)
1070 max_speed = 8;
1071 else if (phba->lmt & LMT_4Gb)
1072 max_speed = 4;
1073 else if (phba->lmt & LMT_2Gb)
1074 max_speed = 2;
1075 else
1076 max_speed = 1;
dea31012005-04-17 16:05:31 -05001077
1078 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001079
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001080 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001081 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001082 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001083 break;
dea31012005-04-17 16:05:31 -05001084 case PCI_DEVICE_ID_SUPERFLY:
1085 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001086 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001087 else
James Smart18a3b592006-12-02 13:35:08 -05001088 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001089 break;
1090 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001091 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001092 break;
1093 case PCI_DEVICE_ID_CENTAUR:
1094 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001095 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001096 else
James Smart18a3b592006-12-02 13:35:08 -05001097 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001098 break;
1099 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001100 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001101 break;
1102 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001103 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001104 break;
1105 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001106 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001107 break;
1108 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001109 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001110 break;
1111 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001112 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001113 break;
1114 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001115 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001116 break;
1117 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001118 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001119 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001120 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001121 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001122 break;
1123 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001124 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001125 break;
1126 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001127 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001128 break;
1129 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001130 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001131 break;
1132 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001133 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001134 break;
dea31012005-04-17 16:05:31 -05001135 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001136 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001137 break;
1138 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001139 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001140 break;
1141 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001142 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001143 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001144 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001145 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001146 break;
1147 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001148 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001149 break;
dea31012005-04-17 16:05:31 -05001150 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001151 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001152 break;
1153 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001154 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001155 break;
1156 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001157 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001158 break;
1159 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001160 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001161 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001162 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001163 m = (typeof(m)){"LP11000-S", max_speed,
1164 "PCI-X2"};
1165 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001166 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001167 m = (typeof(m)){"LPe11000-S", max_speed,
1168 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001169 break;
James Smartb87eab32007-04-25 09:53:28 -04001170 case PCI_DEVICE_ID_SAT:
1171 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1172 break;
1173 case PCI_DEVICE_ID_SAT_MID:
1174 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1175 break;
1176 case PCI_DEVICE_ID_SAT_SMB:
1177 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1178 break;
1179 case PCI_DEVICE_ID_SAT_DCSP:
1180 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1181 break;
1182 case PCI_DEVICE_ID_SAT_SCSP:
1183 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1184 break;
1185 case PCI_DEVICE_ID_SAT_S:
1186 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1187 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001188 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001189 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001190 break;
dea31012005-04-17 16:05:31 -05001191 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001192
1193 if (mdp && mdp[0] == '\0')
1194 snprintf(mdp, 79,"%s", m.name);
1195 if (descp && descp[0] == '\0')
1196 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001197 "Emulex %s %dGb %s Fibre Channel Adapter",
1198 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001199}
1200
1201/**************************************************/
1202/* lpfc_post_buffer */
1203/* */
1204/* This routine will post count buffers to the */
1205/* ring with the QUE_RING_BUF_CN command. This */
1206/* allows 3 buffers / command to be posted. */
1207/* Returns the number of buffers NOT posted. */
1208/**************************************************/
1209int
James Smart2e0fef82007-06-17 19:56:36 -05001210lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -05001211 int type)
1212{
1213 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001214 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001215 struct lpfc_dmabuf *mp1, *mp2;
1216
1217 cnt += pring->missbufcnt;
1218
1219 /* While there are buffers to post */
1220 while (cnt > 0) {
1221 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001222 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001223 if (iocb == NULL) {
1224 pring->missbufcnt = cnt;
1225 return cnt;
1226 }
dea31012005-04-17 16:05:31 -05001227 icmd = &iocb->iocb;
1228
1229 /* 2 buffers can be posted per command */
1230 /* Allocate buffer to post */
1231 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1232 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001233 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1234 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001235 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001236 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001237 pring->missbufcnt = cnt;
1238 return cnt;
1239 }
1240
1241 INIT_LIST_HEAD(&mp1->list);
1242 /* Allocate buffer to post */
1243 if (cnt > 1) {
1244 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1245 if (mp2)
1246 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1247 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001248 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001249 kfree(mp2);
dea31012005-04-17 16:05:31 -05001250 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1251 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001252 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001253 pring->missbufcnt = cnt;
1254 return cnt;
1255 }
1256
1257 INIT_LIST_HEAD(&mp2->list);
1258 } else {
1259 mp2 = NULL;
1260 }
1261
1262 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1263 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1264 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1265 icmd->ulpBdeCount = 1;
1266 cnt--;
1267 if (mp2) {
1268 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1269 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1270 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1271 cnt--;
1272 icmd->ulpBdeCount = 2;
1273 }
1274
1275 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1276 icmd->ulpLe = 1;
1277
dea31012005-04-17 16:05:31 -05001278 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1279 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1280 kfree(mp1);
1281 cnt++;
1282 if (mp2) {
1283 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1284 kfree(mp2);
1285 cnt++;
1286 }
James Bottomley604a3e32005-10-29 10:28:33 -05001287 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001288 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001289 return cnt;
1290 }
dea31012005-04-17 16:05:31 -05001291 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001292 if (mp2)
dea31012005-04-17 16:05:31 -05001293 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001294 }
1295 pring->missbufcnt = 0;
1296 return 0;
1297}
1298
1299/************************************************************************/
1300/* */
1301/* lpfc_post_rcv_buf */
1302/* This routine post initial rcv buffers to the configured rings */
1303/* */
1304/************************************************************************/
1305static int
James Smart2e0fef82007-06-17 19:56:36 -05001306lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001307{
1308 struct lpfc_sli *psli = &phba->sli;
1309
1310 /* Ring 0, ELS / CT buffers */
1311 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1312 /* Ring 2 - FCP no buffers needed */
1313
1314 return 0;
1315}
1316
1317#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1318
1319/************************************************************************/
1320/* */
1321/* lpfc_sha_init */
1322/* */
1323/************************************************************************/
1324static void
1325lpfc_sha_init(uint32_t * HashResultPointer)
1326{
1327 HashResultPointer[0] = 0x67452301;
1328 HashResultPointer[1] = 0xEFCDAB89;
1329 HashResultPointer[2] = 0x98BADCFE;
1330 HashResultPointer[3] = 0x10325476;
1331 HashResultPointer[4] = 0xC3D2E1F0;
1332}
1333
1334/************************************************************************/
1335/* */
1336/* lpfc_sha_iterate */
1337/* */
1338/************************************************************************/
1339static void
1340lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1341{
1342 int t;
1343 uint32_t TEMP;
1344 uint32_t A, B, C, D, E;
1345 t = 16;
1346 do {
1347 HashWorkingPointer[t] =
1348 S(1,
1349 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1350 8] ^
1351 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1352 } while (++t <= 79);
1353 t = 0;
1354 A = HashResultPointer[0];
1355 B = HashResultPointer[1];
1356 C = HashResultPointer[2];
1357 D = HashResultPointer[3];
1358 E = HashResultPointer[4];
1359
1360 do {
1361 if (t < 20) {
1362 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1363 } else if (t < 40) {
1364 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1365 } else if (t < 60) {
1366 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1367 } else {
1368 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1369 }
1370 TEMP += S(5, A) + E + HashWorkingPointer[t];
1371 E = D;
1372 D = C;
1373 C = S(30, B);
1374 B = A;
1375 A = TEMP;
1376 } while (++t <= 79);
1377
1378 HashResultPointer[0] += A;
1379 HashResultPointer[1] += B;
1380 HashResultPointer[2] += C;
1381 HashResultPointer[3] += D;
1382 HashResultPointer[4] += E;
1383
1384}
1385
1386/************************************************************************/
1387/* */
1388/* lpfc_challenge_key */
1389/* */
1390/************************************************************************/
1391static void
1392lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1393{
1394 *HashWorking = (*RandomChallenge ^ *HashWorking);
1395}
1396
1397/************************************************************************/
1398/* */
1399/* lpfc_hba_init */
1400/* */
1401/************************************************************************/
1402void
1403lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1404{
1405 int t;
1406 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001407 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001408
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001409 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001410 if (!HashWorking)
1411 return;
1412
dea31012005-04-17 16:05:31 -05001413 HashWorking[0] = HashWorking[78] = *pwwnn++;
1414 HashWorking[1] = HashWorking[79] = *pwwnn;
1415
1416 for (t = 0; t < 7; t++)
1417 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1418
1419 lpfc_sha_init(hbainit);
1420 lpfc_sha_iterate(hbainit, HashWorking);
1421 kfree(HashWorking);
1422}
1423
James Smart87af33f2007-10-27 13:37:43 -04001424void
James Smart2e0fef82007-06-17 19:56:36 -05001425lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001426{
James Smart87af33f2007-10-27 13:37:43 -04001427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001428 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001429 int i = 0;
dea31012005-04-17 16:05:31 -05001430
James Smart87af33f2007-10-27 13:37:43 -04001431 if (phba->link_state > LPFC_LINK_DOWN)
1432 lpfc_port_link_failure(vport);
1433
1434 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001435 if (!NLP_CHK_NODE_ACT(ndlp)) {
1436 ndlp = lpfc_enable_node(vport, ndlp,
1437 NLP_STE_UNUSED_NODE);
1438 if (!ndlp)
1439 continue;
1440 spin_lock_irq(&phba->ndlp_lock);
1441 NLP_SET_FREE_REQ(ndlp);
1442 spin_unlock_irq(&phba->ndlp_lock);
1443 /* Trigger the release of the ndlp memory */
1444 lpfc_nlp_put(ndlp);
1445 continue;
1446 }
1447 spin_lock_irq(&phba->ndlp_lock);
1448 if (NLP_CHK_FREE_REQ(ndlp)) {
1449 /* The ndlp should not be in memory free mode already */
1450 spin_unlock_irq(&phba->ndlp_lock);
1451 continue;
1452 } else
1453 /* Indicate request for freeing ndlp memory */
1454 NLP_SET_FREE_REQ(ndlp);
1455 spin_unlock_irq(&phba->ndlp_lock);
1456
James Smart87af33f2007-10-27 13:37:43 -04001457 if (ndlp->nlp_type & NLP_FABRIC)
1458 lpfc_disc_state_machine(vport, ndlp, NULL,
1459 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001460
James Smart87af33f2007-10-27 13:37:43 -04001461 lpfc_disc_state_machine(vport, ndlp, NULL,
1462 NLP_EVT_DEVICE_RM);
1463 }
1464
James Smarta8adb832007-10-27 13:37:53 -04001465 /* At this point, ALL ndlp's should be gone
1466 * because of the previous NLP_EVT_DEVICE_RM.
1467 * Lets wait for this to happen, if needed.
1468 */
James Smart87af33f2007-10-27 13:37:43 -04001469 while (!list_empty(&vport->fc_nodes)) {
1470
James Smarta8adb832007-10-27 13:37:53 -04001471 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001472 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001473 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001474 list_for_each_entry_safe(ndlp, next_ndlp,
1475 &vport->fc_nodes, nlp_listp) {
1476 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1477 LOG_NODE,
1478 "0282: did:x%x ndlp:x%p "
1479 "usgmap:x%x refcnt:%d\n",
1480 ndlp->nlp_DID, (void *)ndlp,
1481 ndlp->nlp_usg_map,
1482 atomic_read(
1483 &ndlp->kref.refcount));
1484 }
James Smarta8adb832007-10-27 13:37:53 -04001485 break;
James Smart87af33f2007-10-27 13:37:43 -04001486 }
James Smarta8adb832007-10-27 13:37:53 -04001487
1488 /* Wait for any activity on ndlps to settle */
1489 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001490 }
dea31012005-04-17 16:05:31 -05001491 return;
1492}
1493
1494static void
1495lpfc_establish_link_tmo(unsigned long ptr)
1496{
James Smart92d7f7b2007-06-17 19:56:38 -05001497 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James Smart549e55c2007-08-02 11:09:51 -04001498 struct lpfc_vport **vports;
dea31012005-04-17 16:05:31 -05001499 unsigned long iflag;
James Smart549e55c2007-08-02 11:09:51 -04001500 int i;
dea31012005-04-17 16:05:31 -05001501
dea31012005-04-17 16:05:31 -05001502 /* Re-establishing Link, timer expired */
1503 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001504 "1300 Re-establishing Link, timer expired "
dea31012005-04-17 16:05:31 -05001505 "Data: x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001506 phba->pport->fc_flag, phba->pport->port_state);
James Smart549e55c2007-08-02 11:09:51 -04001507 vports = lpfc_create_vport_work_array(phba);
1508 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001509 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001510 struct Scsi_Host *shost;
1511 shost = lpfc_shost_from_vport(vports[i]);
1512 spin_lock_irqsave(shost->host_lock, iflag);
1513 vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1514 spin_unlock_irqrestore(shost->host_lock, iflag);
1515 }
James Smart09372822008-01-11 01:52:54 -05001516 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001517}
1518
James Smart92d7f7b2007-06-17 19:56:38 -05001519void
1520lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001521{
James Smart92d7f7b2007-06-17 19:56:38 -05001522 del_timer_sync(&vport->els_tmofunc);
1523 del_timer_sync(&vport->fc_fdmitmo);
1524 lpfc_can_disctmo(vport);
1525 return;
dea31012005-04-17 16:05:31 -05001526}
1527
James Smart2e0fef82007-06-17 19:56:36 -05001528static void
James Smart92d7f7b2007-06-17 19:56:38 -05001529lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001530{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001531 del_timer_sync(&phba->fcp_poll_timer);
dea31012005-04-17 16:05:31 -05001532 del_timer_sync(&phba->fc_estabtmo);
James Smart51ef4c22007-08-02 11:10:31 -04001533 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001534 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001535 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001536 phba->hb_outstanding = 0;
1537 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001538 return;
dea31012005-04-17 16:05:31 -05001539}
1540
Adrian Bunka6ababd2007-11-05 18:07:33 +01001541static void
1542lpfc_block_mgmt_io(struct lpfc_hba * phba)
1543{
1544 unsigned long iflag;
1545
1546 spin_lock_irqsave(&phba->hbalock, iflag);
1547 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1548 spin_unlock_irqrestore(&phba->hbalock, iflag);
1549}
1550
dea31012005-04-17 16:05:31 -05001551int
James Smart2e0fef82007-06-17 19:56:36 -05001552lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001553{
James Smart2e0fef82007-06-17 19:56:36 -05001554 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001555 struct lpfc_vport **vports;
1556 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001557
dea31012005-04-17 16:05:31 -05001558 if (!phba)
1559 return 0;
1560
James Smart2e0fef82007-06-17 19:56:36 -05001561 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001562 return 0;
1563
James Smarted957682007-06-17 19:56:37 -05001564 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001565 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001566
James Smart46fa3112007-04-25 09:51:45 -04001567 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001568
James Smart46fa3112007-04-25 09:51:45 -04001569 if (!lpfc_sli_queue_setup(phba)) {
1570 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001571 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001572 }
1573
1574 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1575 lpfc_unblock_mgmt_io(phba);
1576 return 1;
1577 }
dea31012005-04-17 16:05:31 -05001578
James Smart549e55c2007-08-02 11:09:51 -04001579 vports = lpfc_create_vport_work_array(phba);
1580 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001581 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001582 struct Scsi_Host *shost;
1583 shost = lpfc_shost_from_vport(vports[i]);
1584 spin_lock_irq(shost->host_lock);
1585 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1586 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1587 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1588 spin_unlock_irq(shost->host_lock);
1589 }
James Smart09372822008-01-11 01:52:54 -05001590 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001591
James Smart46fa3112007-04-25 09:51:45 -04001592 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001593 return 0;
1594}
1595
James Smart46fa3112007-04-25 09:51:45 -04001596void
James Smart46fa3112007-04-25 09:51:45 -04001597lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1598{
1599 unsigned long iflag;
1600
James Smart2e0fef82007-06-17 19:56:36 -05001601 spin_lock_irqsave(&phba->hbalock, iflag);
1602 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1603 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001604}
1605
1606void
1607lpfc_offline_prep(struct lpfc_hba * phba)
1608{
James Smart2e0fef82007-06-17 19:56:36 -05001609 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001610 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001611 struct lpfc_vport **vports;
1612 int i;
dea31012005-04-17 16:05:31 -05001613
James Smart2e0fef82007-06-17 19:56:36 -05001614 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001615 return;
dea31012005-04-17 16:05:31 -05001616
James Smart46fa3112007-04-25 09:51:45 -04001617 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001618
1619 lpfc_linkdown(phba);
1620
James Smart87af33f2007-10-27 13:37:43 -04001621 /* Issue an unreg_login to all nodes on all vports */
1622 vports = lpfc_create_vport_work_array(phba);
1623 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001624 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001625 struct Scsi_Host *shost;
1626
James Smarta8adb832007-10-27 13:37:53 -04001627 if (vports[i]->load_flag & FC_UNLOADING)
1628 continue;
James Smart87af33f2007-10-27 13:37:43 -04001629 shost = lpfc_shost_from_vport(vports[i]);
1630 list_for_each_entry_safe(ndlp, next_ndlp,
1631 &vports[i]->fc_nodes,
1632 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001633 if (!NLP_CHK_NODE_ACT(ndlp))
1634 continue;
James Smart87af33f2007-10-27 13:37:43 -04001635 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1636 continue;
1637 if (ndlp->nlp_type & NLP_FABRIC) {
1638 lpfc_disc_state_machine(vports[i], ndlp,
1639 NULL, NLP_EVT_DEVICE_RECOVERY);
1640 lpfc_disc_state_machine(vports[i], ndlp,
1641 NULL, NLP_EVT_DEVICE_RM);
1642 }
1643 spin_lock_irq(shost->host_lock);
1644 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1645 spin_unlock_irq(shost->host_lock);
1646 lpfc_unreg_rpi(vports[i], ndlp);
1647 }
1648 }
1649 }
James Smart09372822008-01-11 01:52:54 -05001650 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001651
James Smart46fa3112007-04-25 09:51:45 -04001652 lpfc_sli_flush_mbox_queue(phba);
1653}
1654
1655void
James Smart2e0fef82007-06-17 19:56:36 -05001656lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001657{
James Smart549e55c2007-08-02 11:09:51 -04001658 struct Scsi_Host *shost;
1659 struct lpfc_vport **vports;
1660 int i;
James Smart46fa3112007-04-25 09:51:45 -04001661
James Smart549e55c2007-08-02 11:09:51 -04001662 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001663 return;
James Smart688a8862006-07-06 15:49:56 -04001664
dea31012005-04-17 16:05:31 -05001665 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001666 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001667 vports = lpfc_create_vport_work_array(phba);
1668 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001669 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001670 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001671 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001672 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001673 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001674 /* Bring down the SLI Layer and cleanup. The HBA is offline
1675 now. */
1676 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001677 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001678 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001679 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001680 vports = lpfc_create_vport_work_array(phba);
1681 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001682 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001683 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001684 spin_lock_irq(shost->host_lock);
1685 vports[i]->work_port_events = 0;
1686 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1687 spin_unlock_irq(shost->host_lock);
1688 }
James Smart09372822008-01-11 01:52:54 -05001689 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001690}
1691
1692/******************************************************************************
1693* Function name: lpfc_scsi_free
1694*
1695* Description: Called from lpfc_pci_remove_one free internal driver resources
1696*
1697******************************************************************************/
1698static int
James Smart2e0fef82007-06-17 19:56:36 -05001699lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001700{
1701 struct lpfc_scsi_buf *sb, *sb_next;
1702 struct lpfc_iocbq *io, *io_next;
1703
James Smart2e0fef82007-06-17 19:56:36 -05001704 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001705 /* Release all the lpfc_scsi_bufs maintained by this host. */
1706 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1707 list_del(&sb->list);
1708 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001709 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001710 kfree(sb);
1711 phba->total_scsi_bufs--;
1712 }
1713
1714 /* Release all the lpfc_iocbq entries maintained by this host. */
1715 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1716 list_del(&io->list);
1717 kfree(io);
1718 phba->total_iocbq_bufs--;
1719 }
1720
James Smart2e0fef82007-06-17 19:56:36 -05001721 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001722
1723 return 0;
1724}
1725
James Smart2e0fef82007-06-17 19:56:36 -05001726struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001727lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001728{
James Smart2e0fef82007-06-17 19:56:36 -05001729 struct lpfc_vport *vport;
1730 struct Scsi_Host *shost;
1731 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001732
James Smart3de2a652007-08-02 11:09:59 -04001733 if (dev != &phba->pcidev->dev)
1734 shost = scsi_host_alloc(&lpfc_vport_template,
1735 sizeof(struct lpfc_vport));
1736 else
1737 shost = scsi_host_alloc(&lpfc_template,
1738 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001739 if (!shost)
1740 goto out;
James Smart47a86172007-04-25 09:53:22 -04001741
James Smart2e0fef82007-06-17 19:56:36 -05001742 vport = (struct lpfc_vport *) shost->hostdata;
1743 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05001744 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001745 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05001746 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04001747
James Smart3de2a652007-08-02 11:09:59 -04001748 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001749 shost->unique_id = instance;
1750 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001751 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001752 shost->this_id = -1;
1753 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001754 /*
James Smart2e0fef82007-06-17 19:56:36 -05001755 * Set initial can_queue value since 0 is no longer supported and
1756 * scsi_add_host will fail. This will be adjusted later based on the
1757 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001758 */
James Smart2e0fef82007-06-17 19:56:36 -05001759 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001760 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001761 shost->transportt = lpfc_vport_transport_template;
1762 vport->port_type = LPFC_NPIV_PORT;
1763 } else {
1764 shost->transportt = lpfc_transport_template;
1765 vport->port_type = LPFC_PHYSICAL_PORT;
1766 }
James Smart47a86172007-04-25 09:53:22 -04001767
James Smart2e0fef82007-06-17 19:56:36 -05001768 /* Initialize all internally managed lists. */
1769 INIT_LIST_HEAD(&vport->fc_nodes);
1770 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001771
James Smart2e0fef82007-06-17 19:56:36 -05001772 init_timer(&vport->fc_disctmo);
1773 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001774 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001775
James Smart2e0fef82007-06-17 19:56:36 -05001776 init_timer(&vport->fc_fdmitmo);
1777 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001778 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001779
James Smart2e0fef82007-06-17 19:56:36 -05001780 init_timer(&vport->els_tmofunc);
1781 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001782 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001783
James Smart3de2a652007-08-02 11:09:59 -04001784 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001785 if (error)
1786 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001787
James Smart549e55c2007-08-02 11:09:51 -04001788 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001789 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001790 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001791 return vport;
James Smart47a86172007-04-25 09:53:22 -04001792
James Smart2e0fef82007-06-17 19:56:36 -05001793out_put_shost:
1794 scsi_host_put(shost);
1795out:
1796 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001797}
1798
James Smart2e0fef82007-06-17 19:56:36 -05001799void
1800destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001801{
James Smart92d7f7b2007-06-17 19:56:38 -05001802 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1803 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001804
James Smart92d7f7b2007-06-17 19:56:38 -05001805 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001806
James Smart858c9f62007-06-17 19:56:39 -05001807 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001808 fc_remove_host(shost);
1809 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001810
James Smart92d7f7b2007-06-17 19:56:38 -05001811 spin_lock_irq(&phba->hbalock);
1812 list_del_init(&vport->listentry);
1813 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001814
James Smart92d7f7b2007-06-17 19:56:38 -05001815 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001816 return;
James Smart47a86172007-04-25 09:53:22 -04001817}
1818
James Smart92d7f7b2007-06-17 19:56:38 -05001819int
1820lpfc_get_instance(void)
1821{
1822 int instance = 0;
1823
1824 /* Assign an unused number */
1825 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1826 return -1;
1827 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1828 return -1;
1829 return instance;
1830}
1831
James Smart858c9f62007-06-17 19:56:39 -05001832/*
1833 * Note: there is no scan_start function as adapter initialization
1834 * will have asynchronously kicked off the link initialization.
1835 */
James Smart47a86172007-04-25 09:53:22 -04001836
1837int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1838{
James Smart2e0fef82007-06-17 19:56:36 -05001839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1840 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001841 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001842
James Smart858c9f62007-06-17 19:56:39 -05001843 spin_lock_irq(shost->host_lock);
1844
James Smart51ef4c22007-08-02 11:10:31 -04001845 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05001846 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001847 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001848 }
James Smart2e0fef82007-06-17 19:56:36 -05001849 if (time >= 30 * HZ) {
1850 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001851 "0461 Scanning longer than 30 "
1852 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001853 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001854 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001855 }
1856 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001858 "0465 Link down longer than 15 "
1859 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001860 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001861 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001862 }
1863
James Smart2e0fef82007-06-17 19:56:36 -05001864 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001865 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001866 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001867 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001868 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001869 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001870 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001871 goto finished;
1872
1873 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001874
1875finished:
James Smart858c9f62007-06-17 19:56:39 -05001876 spin_unlock_irq(shost->host_lock);
1877 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001878}
1879
1880void lpfc_host_attrib_init(struct Scsi_Host *shost)
1881{
1882 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1883 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001884 /*
James Smart2e0fef82007-06-17 19:56:36 -05001885 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001886 */
1887
James Smart2e0fef82007-06-17 19:56:36 -05001888 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1889 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001890 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1891
1892 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001893 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001894 fc_host_supported_fc4s(shost)[2] = 1;
1895 fc_host_supported_fc4s(shost)[7] = 1;
1896
James Smart92d7f7b2007-06-17 19:56:38 -05001897 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1898 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001899
1900 fc_host_supported_speeds(shost) = 0;
1901 if (phba->lmt & LMT_10Gb)
1902 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04001903 if (phba->lmt & LMT_8Gb)
1904 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04001905 if (phba->lmt & LMT_4Gb)
1906 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1907 if (phba->lmt & LMT_2Gb)
1908 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1909 if (phba->lmt & LMT_1Gb)
1910 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1911
1912 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001913 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1914 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001915
1916 /* This value is also unchanging */
1917 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001918 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001919 fc_host_active_fc4s(shost)[2] = 1;
1920 fc_host_active_fc4s(shost)[7] = 1;
1921
James Smart92d7f7b2007-06-17 19:56:38 -05001922 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001923 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001924 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001925 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001926}
dea31012005-04-17 16:05:31 -05001927
James Smartdb2378e2008-02-08 18:49:51 -05001928static int
1929lpfc_enable_msix(struct lpfc_hba *phba)
1930{
1931 int error;
1932
1933 phba->msix_entries[0].entry = 0;
1934 phba->msix_entries[0].vector = 0;
1935
1936 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
1937 ARRAY_SIZE(phba->msix_entries));
1938 if (error) {
1939 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1940 "0420 Enable MSI-X failed (%d), continuing "
1941 "with MSI\n", error);
1942 pci_disable_msix(phba->pcidev);
1943 return error;
1944 }
1945
1946 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
1947 LPFC_DRIVER_NAME, phba);
1948 if (error) {
1949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1950 "0421 MSI-X request_irq failed (%d), "
1951 "continuing with MSI\n", error);
1952 pci_disable_msix(phba->pcidev);
1953 }
1954 return error;
1955}
1956
1957static void
1958lpfc_disable_msix(struct lpfc_hba *phba)
1959{
1960 free_irq(phba->msix_entries[0].vector, phba);
1961 pci_disable_msix(phba->pcidev);
1962}
1963
dea31012005-04-17 16:05:31 -05001964static int __devinit
1965lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1966{
James Smart2e0fef82007-06-17 19:56:36 -05001967 struct lpfc_vport *vport = NULL;
1968 struct lpfc_hba *phba;
1969 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001970 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001971 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04001972 void *ptr;
dea31012005-04-17 16:05:31 -05001973 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04001974 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04001975 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05001976 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001977 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05001978
Greg Kroah-Hartmand5f78fb2008-02-02 12:13:22 +01001979 if (pci_enable_device_mem(pdev))
dea31012005-04-17 16:05:31 -05001980 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001981 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05001982 goto out_disable_device;
1983
James Smart2e0fef82007-06-17 19:56:36 -05001984 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1985 if (!phba)
dea31012005-04-17 16:05:31 -05001986 goto out_release_regions;
1987
James Smart2e0fef82007-06-17 19:56:36 -05001988 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001989
James Smarte47c9092008-02-08 18:49:26 -05001990 /* Initialize ndlp management spinlock */
1991 spin_lock_init(&phba->ndlp_lock);
1992
dea31012005-04-17 16:05:31 -05001993 phba->pcidev = pdev;
1994
1995 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001996 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001997 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001998
James Smart2e0fef82007-06-17 19:56:36 -05001999 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05002000 /*
2001 * Get all the module params for configuring this host and then
2002 * establish the host.
2003 */
2004 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002005 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05002006
2007 /* Initialize timers used by driver */
2008 init_timer(&phba->fc_estabtmo);
2009 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
2010 phba->fc_estabtmo.data = (unsigned long)phba;
dea31012005-04-17 16:05:31 -05002011
James Smart858c9f62007-06-17 19:56:39 -05002012 init_timer(&phba->hb_tmofunc);
2013 phba->hb_tmofunc.function = lpfc_hb_timeout;
2014 phba->hb_tmofunc.data = (unsigned long)phba;
2015
dea31012005-04-17 16:05:31 -05002016 psli = &phba->sli;
2017 init_timer(&psli->mbox_tmo);
2018 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002019 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002020 init_timer(&phba->fcp_poll_timer);
2021 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05002022 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002023 init_timer(&phba->fabric_block_timer);
2024 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2025 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05002026
dea31012005-04-17 16:05:31 -05002027 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07002028 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05002029
2030 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2031 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2032 goto out_idr_remove;
2033
2034 /*
2035 * Get the bus address of Bar0 and Bar2 and the number of bytes
2036 * required by each mapping.
2037 */
2038 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2039 bar0map_len = pci_resource_len(phba->pcidev, 0);
2040
2041 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2042 bar2map_len = pci_resource_len(phba->pcidev, 2);
2043
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002044 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002045 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002046 if (!phba->slim_memmap_p) {
2047 error = -ENODEV;
2048 dev_printk(KERN_ERR, &pdev->dev,
2049 "ioremap failed for SLIM memory.\n");
2050 goto out_idr_remove;
2051 }
2052
2053 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05002054 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002055 if (!phba->ctrl_regs_memmap_p) {
2056 error = -ENODEV;
2057 dev_printk(KERN_ERR, &pdev->dev,
2058 "ioremap failed for HBA control registers.\n");
2059 goto out_iounmap_slim;
2060 }
dea31012005-04-17 16:05:31 -05002061
2062 /* Allocate memory for SLI-2 structures */
2063 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
2064 &phba->slim2p_mapping, GFP_KERNEL);
2065 if (!phba->slim2p)
2066 goto out_iounmap;
2067
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04002068 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05002069
James Smarted957682007-06-17 19:56:37 -05002070 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2071 lpfc_sli_hbq_size(),
2072 &phba->hbqslimp.phys,
2073 GFP_KERNEL);
2074 if (!phba->hbqslimp.virt)
2075 goto out_free_slim;
2076
James Smart51ef4c22007-08-02 11:10:31 -04002077 hbq_count = lpfc_sli_hbq_count();
2078 ptr = phba->hbqslimp.virt;
2079 for (i = 0; i < hbq_count; ++i) {
2080 phba->hbqs[i].hbq_virt = ptr;
2081 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2082 ptr += (lpfc_hbq_defs[i]->entry_count *
2083 sizeof(struct lpfc_hbq_entry));
2084 }
2085 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2086 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2087
James Smarted957682007-06-17 19:56:37 -05002088 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2089
James Smart3163f722008-02-08 18:50:25 -05002090 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2091
dea31012005-04-17 16:05:31 -05002092 /* Initialize the SLI Layer to run with lpfc HBAs. */
2093 lpfc_sli_setup(phba);
2094 lpfc_sli_queue_setup(phba);
2095
James Smart98c9ea52007-10-27 13:37:33 -04002096 retval = lpfc_mem_alloc(phba);
2097 if (retval) {
2098 error = retval;
James Smarted957682007-06-17 19:56:37 -05002099 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002100 }
dea31012005-04-17 16:05:31 -05002101
2102 /* Initialize and populate the iocb list per host. */
2103 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2104 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002105 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002106 if (iocbq_entry == NULL) {
2107 printk(KERN_ERR "%s: only allocated %d iocbs of "
2108 "expected %d count. Unloading driver.\n",
2109 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
2110 error = -ENOMEM;
2111 goto out_free_iocbq;
2112 }
2113
James Bottomley604a3e32005-10-29 10:28:33 -05002114 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2115 if (iotag == 0) {
2116 kfree (iocbq_entry);
2117 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2118 "Unloading driver.\n",
2119 __FUNCTION__);
2120 error = -ENOMEM;
2121 goto out_free_iocbq;
2122 }
James Smart2e0fef82007-06-17 19:56:36 -05002123
2124 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002125 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2126 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002127 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002128 }
2129
2130 /* Initialize HBA structure */
2131 phba->fc_edtov = FF_DEF_EDTOV;
2132 phba->fc_ratov = FF_DEF_RATOV;
2133 phba->fc_altov = FF_DEF_ALTOV;
2134 phba->fc_arbtov = FF_DEF_ARBTOV;
2135
2136 INIT_LIST_HEAD(&phba->work_list);
2137 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2138 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2139
2140 /* Startup the kernel thread for this host adapter. */
2141 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2142 "lpfc_worker_%d", phba->brd_no);
2143 if (IS_ERR(phba->worker_thread)) {
2144 error = PTR_ERR(phba->worker_thread);
2145 goto out_free_iocbq;
2146 }
2147
dea31012005-04-17 16:05:31 -05002148 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002149 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002150 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2151
James Smart92d7f7b2007-06-17 19:56:38 -05002152 /* Initialize list of fabric iocbs */
2153 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2154
James Smart0ff10d42008-01-11 01:52:36 -05002155 /* Initialize list to save ELS buffers */
2156 INIT_LIST_HEAD(&phba->elsbuf);
2157
James Smart3de2a652007-08-02 11:09:59 -04002158 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002159 if (!vport)
2160 goto out_kthread_stop;
2161
2162 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002163 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002164 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002165
James Smart92d7f7b2007-06-17 19:56:38 -05002166 pci_set_drvdata(pdev, shost);
James Smartdb2378e2008-02-08 18:49:51 -05002167 phba->intr_type = NONE;
dea31012005-04-17 16:05:31 -05002168
James Smartdb2378e2008-02-08 18:49:51 -05002169 if (phba->cfg_use_msi == 2) {
2170 error = lpfc_enable_msix(phba);
2171 if (!error)
2172 phba->intr_type = MSIX;
2173 }
2174
2175 /* Fallback to MSI if MSI-X initialization failed */
2176 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
James Smart98c9ea52007-10-27 13:37:33 -04002177 retval = pci_enable_msi(phba->pcidev);
2178 if (!retval)
James Smartdb2378e2008-02-08 18:49:51 -05002179 phba->intr_type = MSI;
James Smart51ef4c22007-08-02 11:10:31 -04002180 else
James Smarte8b62012007-08-02 11:10:09 -04002181 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2182 "0452 Enable MSI failed, continuing "
2183 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002184 }
2185
James Smartdb2378e2008-02-08 18:49:51 -05002186 /* MSI-X is the only case the doesn't need to call request_irq */
2187 if (phba->intr_type != MSIX) {
2188 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2189 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2190 if (retval) {
2191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2192 "interrupt handler failed\n");
2193 error = retval;
2194 goto out_disable_msi;
2195 } else if (phba->intr_type != MSI)
2196 phba->intr_type = INTx;
dea31012005-04-17 16:05:31 -05002197 }
dea31012005-04-17 16:05:31 -05002198
James Smart2e0fef82007-06-17 19:56:36 -05002199 phba->MBslimaddr = phba->slim_memmap_p;
2200 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2201 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2202 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2203 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2204
James Smart98c9ea52007-10-27 13:37:33 -04002205 if (lpfc_alloc_sysfs_attr(vport)) {
2206 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002207 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002208 }
dea31012005-04-17 16:05:31 -05002209
James Smart98c9ea52007-10-27 13:37:33 -04002210 if (lpfc_sli_hba_setup(phba)) {
2211 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002212 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002213 }
James Smart858c9f62007-06-17 19:56:39 -05002214
2215 /*
2216 * hba setup may have changed the hba_queue_depth so we need to adjust
2217 * the value of can_queue.
2218 */
2219 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2220
2221 lpfc_host_attrib_init(shost);
2222
James Smart2e0fef82007-06-17 19:56:36 -05002223 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2224 spin_lock_irq(shost->host_lock);
2225 lpfc_poll_start_timer(phba);
2226 spin_unlock_irq(shost->host_lock);
2227 }
James Smart8f6d98d2006-08-01 07:34:00 -04002228
James Smart858c9f62007-06-17 19:56:39 -05002229 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002230
dea31012005-04-17 16:05:31 -05002231 return 0;
2232
James Smart858c9f62007-06-17 19:56:39 -05002233out_remove_device:
2234 lpfc_free_sysfs_attr(vport);
2235 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002236 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002237 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002238out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002239 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002240 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05002241
2242 if (phba->intr_type == MSIX)
2243 lpfc_disable_msix(phba);
2244 else
2245 free_irq(phba->pcidev->irq, phba);
2246
James Smart92d7f7b2007-06-17 19:56:38 -05002247out_disable_msi:
James Smartdb2378e2008-02-08 18:49:51 -05002248 if (phba->intr_type == MSI)
James Smart51ef4c22007-08-02 11:10:31 -04002249 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002250 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002251out_kthread_stop:
2252 kthread_stop(phba->worker_thread);
2253out_free_iocbq:
2254 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2255 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002256 kfree(iocbq_entry);
2257 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002258 }
2259 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002260out_free_hbqslimp:
2261 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2262 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002263out_free_slim:
2264 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2265 phba->slim2p_mapping);
2266out_iounmap:
2267 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002268out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002269 iounmap(phba->slim_memmap_p);
2270out_idr_remove:
2271 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002272out_free_phba:
2273 kfree(phba);
dea31012005-04-17 16:05:31 -05002274out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002275 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002276out_disable_device:
2277 pci_disable_device(pdev);
2278out:
James Smartdefbcf12006-04-16 22:26:50 -04002279 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002280 if (shost)
2281 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002282 return error;
2283}
2284
2285static void __devexit
2286lpfc_pci_remove_one(struct pci_dev *pdev)
2287{
James Smart2e0fef82007-06-17 19:56:36 -05002288 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2290 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002291 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2292
James Smart549e55c2007-08-02 11:09:51 -04002293 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002294 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002295 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002296
James Smart858c9f62007-06-17 19:56:39 -05002297 kfree(vport->vname);
2298 lpfc_free_sysfs_attr(vport);
2299
James Smart09372822008-01-11 01:52:54 -05002300 kthread_stop(phba->worker_thread);
2301
James Smart858c9f62007-06-17 19:56:39 -05002302 fc_remove_host(shost);
2303 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002304 lpfc_cleanup(vport);
2305
James Smart2e0fef82007-06-17 19:56:36 -05002306 /*
2307 * Bring down the SLI Layer. This step disable all interrupts,
2308 * clears the rings, discards all mailbox commands, and resets
2309 * the HBA.
2310 */
2311 lpfc_sli_hba_down(phba);
2312 lpfc_sli_brdrestart(phba);
2313
James Smart92d7f7b2007-06-17 19:56:38 -05002314 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002315 spin_lock_irq(&phba->hbalock);
2316 list_del_init(&vport->listentry);
2317 spin_unlock_irq(&phba->hbalock);
2318
James Smart858c9f62007-06-17 19:56:39 -05002319 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002320
James Smartdb2378e2008-02-08 18:49:51 -05002321 if (phba->intr_type == MSIX)
2322 lpfc_disable_msix(phba);
2323 else {
2324 free_irq(phba->pcidev->irq, phba);
2325 if (phba->intr_type == MSI)
2326 pci_disable_msi(phba->pcidev);
2327 }
dea31012005-04-17 16:05:31 -05002328
2329 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002330 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002331
2332 /*
2333 * Call scsi_free before mem_free since scsi bufs are released to their
2334 * corresponding pools here.
2335 */
2336 lpfc_scsi_free(phba);
2337 lpfc_mem_free(phba);
2338
James Smarted957682007-06-17 19:56:37 -05002339 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2340 phba->hbqslimp.phys);
2341
James Smart2e0fef82007-06-17 19:56:36 -05002342 /* Free resources associated with SLI2 interface */
2343 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2344 phba->slim2p, phba->slim2p_mapping);
2345
2346 /* unmap adapter SLIM and Control Registers */
2347 iounmap(phba->ctrl_regs_memmap_p);
2348 iounmap(phba->slim_memmap_p);
2349
2350 idr_remove(&lpfc_hba_index, phba->brd_no);
2351
2352 kfree(phba);
2353
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002354 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002355 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002356}
2357
Linas Vepstas8d63f372007-02-14 14:28:36 -06002358/**
2359 * lpfc_io_error_detected - called when PCI error is detected
2360 * @pdev: Pointer to PCI device
2361 * @state: The current pci conneection state
2362 *
2363 * This function is called after a PCI bus error affecting
2364 * this device has been detected.
2365 */
2366static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2367 pci_channel_state_t state)
2368{
James Smart51ef4c22007-08-02 11:10:31 -04002369 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2370 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002371 struct lpfc_sli *psli = &phba->sli;
2372 struct lpfc_sli_ring *pring;
2373
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002374 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002375 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002376
Linas Vepstas8d63f372007-02-14 14:28:36 -06002377 pci_disable_device(pdev);
2378 /*
2379 * There may be I/Os dropped by the firmware.
2380 * Error iocb (I/O) on txcmplq and let the SCSI layer
2381 * retry it after re-establishing link.
2382 */
2383 pring = &psli->ring[psli->fcp_ring];
2384 lpfc_sli_abort_iocb_ring(phba, pring);
2385
James Smartdb2378e2008-02-08 18:49:51 -05002386 if (phba->intr_type == MSIX)
2387 lpfc_disable_msix(phba);
2388 else {
2389 free_irq(phba->pcidev->irq, phba);
2390 if (phba->intr_type == MSI)
2391 pci_disable_msi(phba->pcidev);
2392 }
James Smart51ef4c22007-08-02 11:10:31 -04002393
Linas Vepstas8d63f372007-02-14 14:28:36 -06002394 /* Request a slot reset. */
2395 return PCI_ERS_RESULT_NEED_RESET;
2396}
2397
2398/**
2399 * lpfc_io_slot_reset - called after the pci bus has been reset.
2400 * @pdev: Pointer to PCI device
2401 *
2402 * Restart the card from scratch, as if from a cold-boot.
2403 */
2404static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2405{
James Smart51ef4c22007-08-02 11:10:31 -04002406 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2407 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002408 struct lpfc_sli *psli = &phba->sli;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002409
2410 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002411 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002412 printk(KERN_ERR "lpfc: Cannot re-enable "
2413 "PCI device after reset.\n");
2414 return PCI_ERS_RESULT_DISCONNECT;
2415 }
2416
2417 pci_set_master(pdev);
2418
2419 /* Re-establishing Link */
James Smart51ef4c22007-08-02 11:10:31 -04002420 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002421 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart51ef4c22007-08-02 11:10:31 -04002422 spin_unlock_irq(shost->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002423
James Smart92d7f7b2007-06-17 19:56:38 -05002424 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002425 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002426 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002427
2428
2429 /* Take device offline; this will perform cleanup */
2430 lpfc_offline(phba);
2431 lpfc_sli_brdrestart(phba);
2432
2433 return PCI_ERS_RESULT_RECOVERED;
2434}
2435
2436/**
2437 * lpfc_io_resume - called when traffic can start flowing again.
2438 * @pdev: Pointer to PCI device
2439 *
2440 * This callback is called when the error recovery driver tells us that
2441 * its OK to resume normal operation.
2442 */
2443static void lpfc_io_resume(struct pci_dev *pdev)
2444{
James Smart51ef4c22007-08-02 11:10:31 -04002445 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2446 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002447
2448 if (lpfc_online(phba) == 0) {
2449 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2450 }
2451}
2452
dea31012005-04-17 16:05:31 -05002453static struct pci_device_id lpfc_id_table[] = {
2454 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2455 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002456 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2457 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002458 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2459 PCI_ANY_ID, PCI_ANY_ID, },
2460 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2461 PCI_ANY_ID, PCI_ANY_ID, },
2462 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2463 PCI_ANY_ID, PCI_ANY_ID, },
2464 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2465 PCI_ANY_ID, PCI_ANY_ID, },
2466 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2467 PCI_ANY_ID, PCI_ANY_ID, },
2468 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2469 PCI_ANY_ID, PCI_ANY_ID, },
2470 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2471 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002472 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2473 PCI_ANY_ID, PCI_ANY_ID, },
2474 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2475 PCI_ANY_ID, PCI_ANY_ID, },
2476 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2477 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002478 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2479 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002480 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2481 PCI_ANY_ID, PCI_ANY_ID, },
2482 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2483 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002484 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2485 PCI_ANY_ID, PCI_ANY_ID, },
2486 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2487 PCI_ANY_ID, PCI_ANY_ID, },
2488 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2489 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002490 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2491 PCI_ANY_ID, PCI_ANY_ID, },
2492 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2493 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002494 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2495 PCI_ANY_ID, PCI_ANY_ID, },
2496 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2497 PCI_ANY_ID, PCI_ANY_ID, },
2498 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2499 PCI_ANY_ID, PCI_ANY_ID, },
2500 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2501 PCI_ANY_ID, PCI_ANY_ID, },
2502 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2503 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002504 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2505 PCI_ANY_ID, PCI_ANY_ID, },
2506 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2507 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002508 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2509 PCI_ANY_ID, PCI_ANY_ID, },
2510 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2511 PCI_ANY_ID, PCI_ANY_ID, },
2512 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2513 PCI_ANY_ID, PCI_ANY_ID, },
2514 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2515 PCI_ANY_ID, PCI_ANY_ID, },
2516 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2517 PCI_ANY_ID, PCI_ANY_ID, },
2518 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2519 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002520 { 0 }
2521};
2522
2523MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2524
Linas Vepstas8d63f372007-02-14 14:28:36 -06002525static struct pci_error_handlers lpfc_err_handler = {
2526 .error_detected = lpfc_io_error_detected,
2527 .slot_reset = lpfc_io_slot_reset,
2528 .resume = lpfc_io_resume,
2529};
2530
dea31012005-04-17 16:05:31 -05002531static struct pci_driver lpfc_driver = {
2532 .name = LPFC_DRIVER_NAME,
2533 .id_table = lpfc_id_table,
2534 .probe = lpfc_pci_probe_one,
2535 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002536 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002537};
2538
2539static int __init
2540lpfc_init(void)
2541{
2542 int error = 0;
2543
2544 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002545 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002546
James Smart7ee5d432007-10-27 13:37:17 -04002547 if (lpfc_enable_npiv) {
2548 lpfc_transport_functions.vport_create = lpfc_vport_create;
2549 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2550 }
dea31012005-04-17 16:05:31 -05002551 lpfc_transport_template =
2552 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002553 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002554 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002555 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002556 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002557 fc_attach_transport(&lpfc_vport_transport_functions);
2558 if (lpfc_vport_transport_template == NULL) {
2559 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002560 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002561 }
James Smart7ee5d432007-10-27 13:37:17 -04002562 }
dea31012005-04-17 16:05:31 -05002563 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002564 if (error) {
dea31012005-04-17 16:05:31 -05002565 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002566 fc_release_transport(lpfc_vport_transport_template);
2567 }
dea31012005-04-17 16:05:31 -05002568
2569 return error;
2570}
2571
2572static void __exit
2573lpfc_exit(void)
2574{
2575 pci_unregister_driver(&lpfc_driver);
2576 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002577 if (lpfc_enable_npiv)
2578 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002579}
2580
2581module_init(lpfc_init);
2582module_exit(lpfc_exit);
2583MODULE_LICENSE("GPL");
2584MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2585MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2586MODULE_VERSION("0:" LPFC_DRIVER_VERSION);