blob: 29b4cf9e059ba1d149f2995316c0af6aeb96419c [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 Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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{
464 /* Disable interrupts */
465 writel(0, phba->HCregaddr);
466 readl(phba->HCregaddr); /* flush */
467
James Smart51ef4c22007-08-02 11:10:31 -0400468 lpfc_cleanup_discovery_resources(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -0500469 return 0;
dea31012005-04-17 16:05:31 -0500470}
471
472/************************************************************************/
473/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500474/* lpfc_hba_down_post */
475/* This routine will do uninitialization after the HBA is reset */
476/* when bringing down the SLI Layer. */
477/* This routine returns 0 on success. Any other return value */
478/* indicates an error. */
479/* */
480/************************************************************************/
481int
James Smart2e0fef82007-06-17 19:56:36 -0500482lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500483{
484 struct lpfc_sli *psli = &phba->sli;
485 struct lpfc_sli_ring *pring;
486 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500487 struct lpfc_iocbq *iocb;
488 IOCB_t *cmd = NULL;
489 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500490 int i;
491
James Smart92d7f7b2007-06-17 19:56:38 -0500492 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
493 lpfc_sli_hbqbuf_free_all(phba);
494 else {
495 /* Cleanup preposted buffers on the ELS ring */
496 pring = &psli->ring[LPFC_ELS_RING];
497 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
498 list_del(&mp->list);
499 pring->postbufq_cnt--;
500 lpfc_mbuf_free(phba, mp->virt, mp->phys);
501 kfree(mp);
502 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500503 }
504
James Smart09372822008-01-11 01:52:54 -0500505 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500506 for (i = 0; i < psli->num_rings; i++) {
507 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500508
509 /* At this point in time the HBA is either reset or DOA. Either
510 * way, nothing should be on txcmplq as it will NEVER complete.
511 */
512 list_splice_init(&pring->txcmplq, &completions);
513 pring->txcmplq_cnt = 0;
514 spin_unlock_irq(&phba->hbalock);
515
516 while (!list_empty(&completions)) {
517 iocb = list_get_first(&completions, struct lpfc_iocbq,
518 list);
519 cmd = &iocb->iocb;
520 list_del_init(&iocb->list);
521
522 if (!iocb->iocb_cmpl)
523 lpfc_sli_release_iocbq(phba, iocb);
524 else {
525 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
526 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
527 (iocb->iocb_cmpl) (phba, iocb, iocb);
528 }
529 }
530
Jamie Wellnitz41415862006-02-28 19:25:27 -0500531 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500532 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500533 }
James Smart09372822008-01-11 01:52:54 -0500534 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500535
536 return 0;
537}
538
James Smart858c9f62007-06-17 19:56:39 -0500539/* HBA heart beat timeout handler */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100540static void
James Smart858c9f62007-06-17 19:56:39 -0500541lpfc_hb_timeout(unsigned long ptr)
542{
543 struct lpfc_hba *phba;
544 unsigned long iflag;
545
546 phba = (struct lpfc_hba *)ptr;
547 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
548 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
549 phba->pport->work_port_events |= WORKER_HB_TMO;
550 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
551
552 if (phba->work_wait)
553 wake_up(phba->work_wait);
554 return;
555}
556
557static void
558lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
559{
560 unsigned long drvr_flag;
561
562 spin_lock_irqsave(&phba->hbalock, drvr_flag);
563 phba->hb_outstanding = 0;
564 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
565
566 mempool_free(pmboxq, phba->mbox_mem_pool);
567 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
568 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400569 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500570 mod_timer(&phba->hb_tmofunc,
571 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
572 return;
573}
574
575void
576lpfc_hb_timeout_handler(struct lpfc_hba *phba)
577{
578 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500579 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500580 int retval;
581 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500582 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500583
584 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400585 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500586 (phba->pport->fc_flag & FC_OFFLINE_MODE))
587 return;
588
589 spin_lock_irq(&phba->pport->work_port_lock);
590 /* If the timer is already canceled do nothing */
591 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
592 spin_unlock_irq(&phba->pport->work_port_lock);
593 return;
594 }
595
596 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
597 jiffies)) {
598 spin_unlock_irq(&phba->pport->work_port_lock);
599 if (!phba->hb_outstanding)
600 mod_timer(&phba->hb_tmofunc,
601 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
602 else
603 mod_timer(&phba->hb_tmofunc,
604 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
605 return;
606 }
607 spin_unlock_irq(&phba->pport->work_port_lock);
608
James Smart0ff10d42008-01-11 01:52:36 -0500609 if (phba->elsbuf_cnt &&
610 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
611 spin_lock_irq(&phba->hbalock);
612 list_splice_init(&phba->elsbuf, &completions);
613 phba->elsbuf_cnt = 0;
614 phba->elsbuf_prev_cnt = 0;
615 spin_unlock_irq(&phba->hbalock);
616
617 while (!list_empty(&completions)) {
618 list_remove_head(&completions, buf_ptr,
619 struct lpfc_dmabuf, list);
620 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
621 kfree(buf_ptr);
622 }
623 }
624 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
625
James Smart858c9f62007-06-17 19:56:39 -0500626 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500627 if (phba->cfg_enable_hba_heartbeat) {
628 if (!phba->hb_outstanding) {
629 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
630 if (!pmboxq) {
631 mod_timer(&phba->hb_tmofunc,
632 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
633 return;
634 }
635
636 lpfc_heart_beat(phba, pmboxq);
637 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
638 pmboxq->vport = phba->pport;
639 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
640
641 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
642 mempool_free(pmboxq, phba->mbox_mem_pool);
643 mod_timer(&phba->hb_tmofunc,
644 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
645 return;
646 }
James Smart858c9f62007-06-17 19:56:39 -0500647 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500648 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
649 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500650 return;
James Smart13815c82008-01-11 01:52:48 -0500651 } else {
652 /*
653 * If heart beat timeout called with hb_outstanding set
654 * we need to take the HBA offline.
655 */
656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
657 "0459 Adapter heartbeat failure, "
658 "taking this port offline.\n");
659
660 spin_lock_irq(&phba->hbalock);
661 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
662 spin_unlock_irq(&phba->hbalock);
663
664 lpfc_offline_prep(phba);
665 lpfc_offline(phba);
666 lpfc_unblock_mgmt_io(phba);
667 phba->link_state = LPFC_HBA_ERROR;
668 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500669 }
James Smart858c9f62007-06-17 19:56:39 -0500670 }
671}
672
James Smart09372822008-01-11 01:52:54 -0500673static void
674lpfc_offline_eratt(struct lpfc_hba *phba)
675{
676 struct lpfc_sli *psli = &phba->sli;
677
678 spin_lock_irq(&phba->hbalock);
679 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
680 spin_unlock_irq(&phba->hbalock);
681 lpfc_offline_prep(phba);
682
683 lpfc_offline(phba);
684 lpfc_reset_barrier(phba);
685 lpfc_sli_brdreset(phba);
686 lpfc_hba_down_post(phba);
687 lpfc_sli_brdready(phba, HS_MBRDY);
688 lpfc_unblock_mgmt_io(phba);
689 phba->link_state = LPFC_HBA_ERROR;
690 return;
691}
692
Jamie Wellnitz41415862006-02-28 19:25:27 -0500693/************************************************************************/
694/* */
dea31012005-04-17 16:05:31 -0500695/* lpfc_handle_eratt */
696/* This routine will handle processing a Host Attention */
697/* Error Status event. This will be initialized */
698/* as a SLI layer callback routine. */
699/* */
700/************************************************************************/
701void
James Smart2e0fef82007-06-17 19:56:36 -0500702lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500703{
James Smart2e0fef82007-06-17 19:56:36 -0500704 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500705 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500706 struct lpfc_sli_ring *pring;
James Smart549e55c2007-08-02 11:09:51 -0400707 struct lpfc_vport **vports;
James Smartd2873e42006-08-18 17:46:43 -0400708 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400709 unsigned long temperature;
710 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500711 struct Scsi_Host *shost;
James Smart549e55c2007-08-02 11:09:51 -0400712 int i;
James Smart2e0fef82007-06-17 19:56:36 -0500713
Linas Vepstas8d63f372007-02-14 14:28:36 -0600714 /* If the pci channel is offline, ignore possible errors,
715 * since we cannot communicate with the pci card anyway. */
716 if (pci_channel_offline(phba->pcidev))
717 return;
James Smart13815c82008-01-11 01:52:48 -0500718 /* If resets are disabled then leave the HBA alone and return */
719 if (!phba->cfg_enable_hba_reset)
720 return;
dea31012005-04-17 16:05:31 -0500721
James Smartf5603512006-12-02 13:35:43 -0500722 if (phba->work_hs & HS_FFER6 ||
723 phba->work_hs & HS_FFER5) {
dea31012005-04-17 16:05:31 -0500724 /* Re-establishing Link */
725 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400726 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500727 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400728 phba->work_hs,
dea31012005-04-17 16:05:31 -0500729 phba->work_status[0], phba->work_status[1]);
James Smart549e55c2007-08-02 11:09:51 -0400730 vports = lpfc_create_vport_work_array(phba);
731 if (vports != NULL)
732 for(i = 0;
James Smart09372822008-01-11 01:52:54 -0500733 i <= phba->max_vpi && vports[i] != NULL;
James Smart549e55c2007-08-02 11:09:51 -0400734 i++){
735 shost = lpfc_shost_from_vport(vports[i]);
736 spin_lock_irq(shost->host_lock);
737 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
738 spin_unlock_irq(shost->host_lock);
739 }
James Smart09372822008-01-11 01:52:54 -0500740 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500741 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500742 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500743 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500744
745 /*
746 * Firmware stops when it triggled erratt with HS_FFER6.
747 * That could cause the I/Os dropped by the firmware.
748 * Error iocb (I/O) on txcmplq and let the SCSI layer
749 * retry it after re-establishing link.
750 */
751 pring = &psli->ring[psli->fcp_ring];
752 lpfc_sli_abort_iocb_ring(phba, pring);
753
754
755 /*
756 * There was a firmware error. Take the hba offline and then
757 * attempt to restart it.
758 */
James Smart46fa3112007-04-25 09:51:45 -0400759 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500760 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500761 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500762 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
763 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
James Smart46fa3112007-04-25 09:51:45 -0400764 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500765 return;
766 }
James Smart46fa3112007-04-25 09:51:45 -0400767 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -0400768 } else if (phba->work_hs & HS_CRIT_TEMP) {
769 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
770 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
771 temp_event_data.event_code = LPFC_CRIT_TEMP;
772 temp_event_data.data = (uint32_t)temperature;
773
774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
775 "0459 Adapter maximum temperature exceeded "
776 "(%ld), taking this port offline "
777 "Data: x%x x%x x%x\n",
778 temperature, phba->work_hs,
779 phba->work_status[0], phba->work_status[1]);
780
781 shost = lpfc_shost_from_vport(phba->pport);
782 fc_host_post_vendor_event(shost, fc_get_event_number(),
783 sizeof(temp_event_data),
784 (char *) &temp_event_data,
785 SCSI_NL_VID_TYPE_PCI
786 | PCI_VENDOR_ID_EMULEX);
787
James Smart7af67052007-10-27 13:38:11 -0400788 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -0400789 phba->over_temp_state = HBA_OVER_TEMP;
790 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500791 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -0400792
dea31012005-04-17 16:05:31 -0500793 } else {
794 /* The if clause above forces this code path when the status
795 * failure is a value other than FFER6. Do not call the offline
796 * twice. This is the adapter hardware error path.
797 */
798 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400799 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500800 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400801 phba->work_hs,
dea31012005-04-17 16:05:31 -0500802 phba->work_status[0], phba->work_status[1]);
803
James Smartd2873e42006-08-18 17:46:43 -0400804 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500805 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500806 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400807 sizeof(event_data), (char *) &event_data,
808 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
809
James Smart09372822008-01-11 01:52:54 -0500810 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -0500811 }
812}
813
814/************************************************************************/
815/* */
816/* lpfc_handle_latt */
817/* This routine will handle processing a Host Attention */
818/* Link Status event. This will be initialized */
819/* as a SLI layer callback routine. */
820/* */
821/************************************************************************/
822void
James Smart2e0fef82007-06-17 19:56:36 -0500823lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500824{
James Smart2e0fef82007-06-17 19:56:36 -0500825 struct lpfc_vport *vport = phba->pport;
826 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500827 LPFC_MBOXQ_t *pmb;
828 volatile uint32_t control;
829 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -0500830 int rc = 0;
dea31012005-04-17 16:05:31 -0500831
832 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500833 if (!pmb) {
834 rc = 1;
dea31012005-04-17 16:05:31 -0500835 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -0500836 }
dea31012005-04-17 16:05:31 -0500837
838 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -0500839 if (!mp) {
840 rc = 2;
dea31012005-04-17 16:05:31 -0500841 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -0500842 }
dea31012005-04-17 16:05:31 -0500843
844 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -0500845 if (!mp->virt) {
846 rc = 3;
dea31012005-04-17 16:05:31 -0500847 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -0500848 }
dea31012005-04-17 16:05:31 -0500849
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500850 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400851 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500852
853 psli->slistat.link_event++;
854 lpfc_read_la(phba, pmb, mp);
855 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500856 pmb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400857 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -0500858 if (rc == MBX_NOT_FINISHED) {
859 rc = 4;
James Smart14691152006-12-02 13:34:28 -0500860 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -0500861 }
dea31012005-04-17 16:05:31 -0500862
863 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500864 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500865 writel(HA_LATT, phba->HAregaddr);
866 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500867 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500868
869 return;
870
James Smart14691152006-12-02 13:34:28 -0500871lpfc_handle_latt_free_mbuf:
872 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500873lpfc_handle_latt_free_mp:
874 kfree(mp);
875lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400876 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500877lpfc_handle_latt_err_exit:
878 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500879 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500880 psli->sli_flag |= LPFC_PROCESS_LA;
881 control = readl(phba->HCregaddr);
882 control |= HC_LAINT_ENA;
883 writel(control, phba->HCregaddr);
884 readl(phba->HCregaddr); /* flush */
885
886 /* Clear Link Attention in HA REG */
887 writel(HA_LATT, phba->HAregaddr);
888 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500889 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500890 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500891 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500892
James Smart09372822008-01-11 01:52:54 -0500893 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
894 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -0500895
896 return;
897}
898
899/************************************************************************/
900/* */
901/* lpfc_parse_vpd */
902/* This routine will parse the VPD data */
903/* */
904/************************************************************************/
905static int
James Smart2e0fef82007-06-17 19:56:36 -0500906lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500907{
908 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500909 int Length;
dea31012005-04-17 16:05:31 -0500910 int i, j;
911 int finished = 0;
912 int index = 0;
913
914 if (!vpd)
915 return 0;
916
917 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500918 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400919 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500920 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
921 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500922 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500923 switch (vpd[index]) {
924 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500925 case 0x91:
dea31012005-04-17 16:05:31 -0500926 index += 1;
927 lenlo = vpd[index];
928 index += 1;
929 lenhi = vpd[index];
930 index += 1;
931 i = ((((unsigned short)lenhi) << 8) + lenlo);
932 index += i;
933 break;
934 case 0x90:
935 index += 1;
936 lenlo = vpd[index];
937 index += 1;
938 lenhi = vpd[index];
939 index += 1;
940 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500941 if (Length > len - index)
942 Length = len - index;
dea31012005-04-17 16:05:31 -0500943 while (Length > 0) {
944 /* Look for Serial Number */
945 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
946 index += 2;
947 i = vpd[index];
948 index += 1;
949 j = 0;
950 Length -= (3+i);
951 while(i--) {
952 phba->SerialNumber[j++] = vpd[index++];
953 if (j == 31)
954 break;
955 }
956 phba->SerialNumber[j] = 0;
957 continue;
958 }
959 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
960 phba->vpd_flag |= VPD_MODEL_DESC;
961 index += 2;
962 i = vpd[index];
963 index += 1;
964 j = 0;
965 Length -= (3+i);
966 while(i--) {
967 phba->ModelDesc[j++] = vpd[index++];
968 if (j == 255)
969 break;
970 }
971 phba->ModelDesc[j] = 0;
972 continue;
973 }
974 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
975 phba->vpd_flag |= VPD_MODEL_NAME;
976 index += 2;
977 i = vpd[index];
978 index += 1;
979 j = 0;
980 Length -= (3+i);
981 while(i--) {
982 phba->ModelName[j++] = vpd[index++];
983 if (j == 79)
984 break;
985 }
986 phba->ModelName[j] = 0;
987 continue;
988 }
989 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
990 phba->vpd_flag |= VPD_PROGRAM_TYPE;
991 index += 2;
992 i = vpd[index];
993 index += 1;
994 j = 0;
995 Length -= (3+i);
996 while(i--) {
997 phba->ProgramType[j++] = vpd[index++];
998 if (j == 255)
999 break;
1000 }
1001 phba->ProgramType[j] = 0;
1002 continue;
1003 }
1004 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1005 phba->vpd_flag |= VPD_PORT;
1006 index += 2;
1007 i = vpd[index];
1008 index += 1;
1009 j = 0;
1010 Length -= (3+i);
1011 while(i--) {
1012 phba->Port[j++] = vpd[index++];
1013 if (j == 19)
1014 break;
1015 }
1016 phba->Port[j] = 0;
1017 continue;
1018 }
1019 else {
1020 index += 2;
1021 i = vpd[index];
1022 index += 1;
1023 index += i;
1024 Length -= (3 + i);
1025 }
1026 }
1027 finished = 0;
1028 break;
1029 case 0x78:
1030 finished = 1;
1031 break;
1032 default:
1033 index ++;
1034 break;
1035 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001036 }
dea31012005-04-17 16:05:31 -05001037
1038 return(1);
1039}
1040
1041static void
James Smart2e0fef82007-06-17 19:56:36 -05001042lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001043{
1044 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001045 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001046 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001047 struct {
1048 char * name;
1049 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001050 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001051 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001052
1053 if (mdp && mdp[0] != '\0'
1054 && descp && descp[0] != '\0')
1055 return;
1056
1057 if (phba->lmt & LMT_10Gb)
1058 max_speed = 10;
1059 else if (phba->lmt & LMT_8Gb)
1060 max_speed = 8;
1061 else if (phba->lmt & LMT_4Gb)
1062 max_speed = 4;
1063 else if (phba->lmt & LMT_2Gb)
1064 max_speed = 2;
1065 else
1066 max_speed = 1;
dea31012005-04-17 16:05:31 -05001067
1068 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001069
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001070 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001071 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001072 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001073 break;
dea31012005-04-17 16:05:31 -05001074 case PCI_DEVICE_ID_SUPERFLY:
1075 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001076 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001077 else
James Smart18a3b592006-12-02 13:35:08 -05001078 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001079 break;
1080 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001081 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001082 break;
1083 case PCI_DEVICE_ID_CENTAUR:
1084 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001085 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001086 else
James Smart18a3b592006-12-02 13:35:08 -05001087 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001088 break;
1089 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001090 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001091 break;
1092 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001093 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001094 break;
1095 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001096 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001097 break;
1098 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001099 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001100 break;
1101 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001102 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001103 break;
1104 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001105 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001106 break;
1107 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001108 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001109 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001110 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001111 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001112 break;
1113 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001114 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001115 break;
1116 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001117 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001118 break;
1119 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001120 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001121 break;
1122 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001123 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001124 break;
dea31012005-04-17 16:05:31 -05001125 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001126 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001127 break;
1128 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001129 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001130 break;
1131 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001132 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001133 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001134 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001135 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001136 break;
1137 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001138 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001139 break;
dea31012005-04-17 16:05:31 -05001140 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001141 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001142 break;
1143 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001144 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001145 break;
1146 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001147 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001148 break;
1149 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001150 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001151 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001152 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001153 m = (typeof(m)){"LP11000-S", max_speed,
1154 "PCI-X2"};
1155 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001156 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001157 m = (typeof(m)){"LPe11000-S", max_speed,
1158 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001159 break;
James Smartb87eab32007-04-25 09:53:28 -04001160 case PCI_DEVICE_ID_SAT:
1161 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1162 break;
1163 case PCI_DEVICE_ID_SAT_MID:
1164 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1165 break;
1166 case PCI_DEVICE_ID_SAT_SMB:
1167 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1168 break;
1169 case PCI_DEVICE_ID_SAT_DCSP:
1170 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1171 break;
1172 case PCI_DEVICE_ID_SAT_SCSP:
1173 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1174 break;
1175 case PCI_DEVICE_ID_SAT_S:
1176 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1177 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001178 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001179 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001180 break;
dea31012005-04-17 16:05:31 -05001181 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001182
1183 if (mdp && mdp[0] == '\0')
1184 snprintf(mdp, 79,"%s", m.name);
1185 if (descp && descp[0] == '\0')
1186 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001187 "Emulex %s %dGb %s Fibre Channel Adapter",
1188 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001189}
1190
1191/**************************************************/
1192/* lpfc_post_buffer */
1193/* */
1194/* This routine will post count buffers to the */
1195/* ring with the QUE_RING_BUF_CN command. This */
1196/* allows 3 buffers / command to be posted. */
1197/* Returns the number of buffers NOT posted. */
1198/**************************************************/
1199int
James Smart2e0fef82007-06-17 19:56:36 -05001200lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -05001201 int type)
1202{
1203 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001204 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001205 struct lpfc_dmabuf *mp1, *mp2;
1206
1207 cnt += pring->missbufcnt;
1208
1209 /* While there are buffers to post */
1210 while (cnt > 0) {
1211 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001212 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001213 if (iocb == NULL) {
1214 pring->missbufcnt = cnt;
1215 return cnt;
1216 }
dea31012005-04-17 16:05:31 -05001217 icmd = &iocb->iocb;
1218
1219 /* 2 buffers can be posted per command */
1220 /* Allocate buffer to post */
1221 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1222 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001223 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1224 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001225 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001226 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001227 pring->missbufcnt = cnt;
1228 return cnt;
1229 }
1230
1231 INIT_LIST_HEAD(&mp1->list);
1232 /* Allocate buffer to post */
1233 if (cnt > 1) {
1234 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1235 if (mp2)
1236 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1237 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001238 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001239 kfree(mp2);
dea31012005-04-17 16:05:31 -05001240 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1241 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001242 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001243 pring->missbufcnt = cnt;
1244 return cnt;
1245 }
1246
1247 INIT_LIST_HEAD(&mp2->list);
1248 } else {
1249 mp2 = NULL;
1250 }
1251
1252 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1253 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1254 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1255 icmd->ulpBdeCount = 1;
1256 cnt--;
1257 if (mp2) {
1258 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1259 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1260 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1261 cnt--;
1262 icmd->ulpBdeCount = 2;
1263 }
1264
1265 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1266 icmd->ulpLe = 1;
1267
dea31012005-04-17 16:05:31 -05001268 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1269 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1270 kfree(mp1);
1271 cnt++;
1272 if (mp2) {
1273 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1274 kfree(mp2);
1275 cnt++;
1276 }
James Bottomley604a3e32005-10-29 10:28:33 -05001277 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001278 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001279 return cnt;
1280 }
dea31012005-04-17 16:05:31 -05001281 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001282 if (mp2)
dea31012005-04-17 16:05:31 -05001283 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001284 }
1285 pring->missbufcnt = 0;
1286 return 0;
1287}
1288
1289/************************************************************************/
1290/* */
1291/* lpfc_post_rcv_buf */
1292/* This routine post initial rcv buffers to the configured rings */
1293/* */
1294/************************************************************************/
1295static int
James Smart2e0fef82007-06-17 19:56:36 -05001296lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001297{
1298 struct lpfc_sli *psli = &phba->sli;
1299
1300 /* Ring 0, ELS / CT buffers */
1301 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1302 /* Ring 2 - FCP no buffers needed */
1303
1304 return 0;
1305}
1306
1307#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1308
1309/************************************************************************/
1310/* */
1311/* lpfc_sha_init */
1312/* */
1313/************************************************************************/
1314static void
1315lpfc_sha_init(uint32_t * HashResultPointer)
1316{
1317 HashResultPointer[0] = 0x67452301;
1318 HashResultPointer[1] = 0xEFCDAB89;
1319 HashResultPointer[2] = 0x98BADCFE;
1320 HashResultPointer[3] = 0x10325476;
1321 HashResultPointer[4] = 0xC3D2E1F0;
1322}
1323
1324/************************************************************************/
1325/* */
1326/* lpfc_sha_iterate */
1327/* */
1328/************************************************************************/
1329static void
1330lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1331{
1332 int t;
1333 uint32_t TEMP;
1334 uint32_t A, B, C, D, E;
1335 t = 16;
1336 do {
1337 HashWorkingPointer[t] =
1338 S(1,
1339 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1340 8] ^
1341 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1342 } while (++t <= 79);
1343 t = 0;
1344 A = HashResultPointer[0];
1345 B = HashResultPointer[1];
1346 C = HashResultPointer[2];
1347 D = HashResultPointer[3];
1348 E = HashResultPointer[4];
1349
1350 do {
1351 if (t < 20) {
1352 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1353 } else if (t < 40) {
1354 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1355 } else if (t < 60) {
1356 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1357 } else {
1358 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1359 }
1360 TEMP += S(5, A) + E + HashWorkingPointer[t];
1361 E = D;
1362 D = C;
1363 C = S(30, B);
1364 B = A;
1365 A = TEMP;
1366 } while (++t <= 79);
1367
1368 HashResultPointer[0] += A;
1369 HashResultPointer[1] += B;
1370 HashResultPointer[2] += C;
1371 HashResultPointer[3] += D;
1372 HashResultPointer[4] += E;
1373
1374}
1375
1376/************************************************************************/
1377/* */
1378/* lpfc_challenge_key */
1379/* */
1380/************************************************************************/
1381static void
1382lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1383{
1384 *HashWorking = (*RandomChallenge ^ *HashWorking);
1385}
1386
1387/************************************************************************/
1388/* */
1389/* lpfc_hba_init */
1390/* */
1391/************************************************************************/
1392void
1393lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1394{
1395 int t;
1396 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001397 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001398
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001399 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001400 if (!HashWorking)
1401 return;
1402
dea31012005-04-17 16:05:31 -05001403 HashWorking[0] = HashWorking[78] = *pwwnn++;
1404 HashWorking[1] = HashWorking[79] = *pwwnn;
1405
1406 for (t = 0; t < 7; t++)
1407 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1408
1409 lpfc_sha_init(hbainit);
1410 lpfc_sha_iterate(hbainit, HashWorking);
1411 kfree(HashWorking);
1412}
1413
James Smart87af33f2007-10-27 13:37:43 -04001414void
James Smart2e0fef82007-06-17 19:56:36 -05001415lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001416{
James Smart87af33f2007-10-27 13:37:43 -04001417 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001418 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001419 int i = 0;
dea31012005-04-17 16:05:31 -05001420
James Smart87af33f2007-10-27 13:37:43 -04001421 if (phba->link_state > LPFC_LINK_DOWN)
1422 lpfc_port_link_failure(vport);
1423
1424 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1425 if (ndlp->nlp_type & NLP_FABRIC)
1426 lpfc_disc_state_machine(vport, ndlp, NULL,
1427 NLP_EVT_DEVICE_RECOVERY);
1428 lpfc_disc_state_machine(vport, ndlp, NULL,
1429 NLP_EVT_DEVICE_RM);
1430 }
1431
James Smarta8adb832007-10-27 13:37:53 -04001432 /* At this point, ALL ndlp's should be gone
1433 * because of the previous NLP_EVT_DEVICE_RM.
1434 * Lets wait for this to happen, if needed.
1435 */
James Smart87af33f2007-10-27 13:37:43 -04001436 while (!list_empty(&vport->fc_nodes)) {
1437
James Smarta8adb832007-10-27 13:37:53 -04001438 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001439 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001440 "0233 Nodelist not empty\n");
1441 break;
James Smart87af33f2007-10-27 13:37:43 -04001442 }
James Smarta8adb832007-10-27 13:37:53 -04001443
1444 /* Wait for any activity on ndlps to settle */
1445 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001446 }
dea31012005-04-17 16:05:31 -05001447 return;
1448}
1449
1450static void
1451lpfc_establish_link_tmo(unsigned long ptr)
1452{
James Smart92d7f7b2007-06-17 19:56:38 -05001453 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James Smart549e55c2007-08-02 11:09:51 -04001454 struct lpfc_vport **vports;
dea31012005-04-17 16:05:31 -05001455 unsigned long iflag;
James Smart549e55c2007-08-02 11:09:51 -04001456 int i;
dea31012005-04-17 16:05:31 -05001457
dea31012005-04-17 16:05:31 -05001458 /* Re-establishing Link, timer expired */
1459 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001460 "1300 Re-establishing Link, timer expired "
dea31012005-04-17 16:05:31 -05001461 "Data: x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001462 phba->pport->fc_flag, phba->pport->port_state);
James Smart549e55c2007-08-02 11:09:51 -04001463 vports = lpfc_create_vport_work_array(phba);
1464 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001465 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001466 struct Scsi_Host *shost;
1467 shost = lpfc_shost_from_vport(vports[i]);
1468 spin_lock_irqsave(shost->host_lock, iflag);
1469 vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1470 spin_unlock_irqrestore(shost->host_lock, iflag);
1471 }
James Smart09372822008-01-11 01:52:54 -05001472 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001473}
1474
James Smart92d7f7b2007-06-17 19:56:38 -05001475void
1476lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001477{
James Smart92d7f7b2007-06-17 19:56:38 -05001478 del_timer_sync(&vport->els_tmofunc);
1479 del_timer_sync(&vport->fc_fdmitmo);
1480 lpfc_can_disctmo(vport);
1481 return;
dea31012005-04-17 16:05:31 -05001482}
1483
James Smart2e0fef82007-06-17 19:56:36 -05001484static void
James Smart92d7f7b2007-06-17 19:56:38 -05001485lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001486{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001487 del_timer_sync(&phba->fcp_poll_timer);
dea31012005-04-17 16:05:31 -05001488 del_timer_sync(&phba->fc_estabtmo);
James Smart51ef4c22007-08-02 11:10:31 -04001489 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001490 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001491 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001492 phba->hb_outstanding = 0;
1493 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001494 return;
dea31012005-04-17 16:05:31 -05001495}
1496
Adrian Bunka6ababd2007-11-05 18:07:33 +01001497static void
1498lpfc_block_mgmt_io(struct lpfc_hba * phba)
1499{
1500 unsigned long iflag;
1501
1502 spin_lock_irqsave(&phba->hbalock, iflag);
1503 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1504 spin_unlock_irqrestore(&phba->hbalock, iflag);
1505}
1506
dea31012005-04-17 16:05:31 -05001507int
James Smart2e0fef82007-06-17 19:56:36 -05001508lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001509{
James Smart2e0fef82007-06-17 19:56:36 -05001510 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001511 struct lpfc_vport **vports;
1512 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001513
dea31012005-04-17 16:05:31 -05001514 if (!phba)
1515 return 0;
1516
James Smart2e0fef82007-06-17 19:56:36 -05001517 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001518 return 0;
1519
James Smarted957682007-06-17 19:56:37 -05001520 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001521 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001522
James Smart46fa3112007-04-25 09:51:45 -04001523 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001524
James Smart46fa3112007-04-25 09:51:45 -04001525 if (!lpfc_sli_queue_setup(phba)) {
1526 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001527 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001528 }
1529
1530 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1531 lpfc_unblock_mgmt_io(phba);
1532 return 1;
1533 }
dea31012005-04-17 16:05:31 -05001534
James Smart549e55c2007-08-02 11:09:51 -04001535 vports = lpfc_create_vport_work_array(phba);
1536 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001537 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001538 struct Scsi_Host *shost;
1539 shost = lpfc_shost_from_vport(vports[i]);
1540 spin_lock_irq(shost->host_lock);
1541 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1542 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1543 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1544 spin_unlock_irq(shost->host_lock);
1545 }
James Smart09372822008-01-11 01:52:54 -05001546 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001547
James Smart46fa3112007-04-25 09:51:45 -04001548 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001549 return 0;
1550}
1551
James Smart46fa3112007-04-25 09:51:45 -04001552void
James Smart46fa3112007-04-25 09:51:45 -04001553lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1554{
1555 unsigned long iflag;
1556
James Smart2e0fef82007-06-17 19:56:36 -05001557 spin_lock_irqsave(&phba->hbalock, iflag);
1558 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1559 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001560}
1561
1562void
1563lpfc_offline_prep(struct lpfc_hba * phba)
1564{
James Smart2e0fef82007-06-17 19:56:36 -05001565 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001566 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001567 struct lpfc_vport **vports;
1568 int i;
dea31012005-04-17 16:05:31 -05001569
James Smart2e0fef82007-06-17 19:56:36 -05001570 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001571 return;
dea31012005-04-17 16:05:31 -05001572
James Smart46fa3112007-04-25 09:51:45 -04001573 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001574
1575 lpfc_linkdown(phba);
1576
James Smart87af33f2007-10-27 13:37:43 -04001577 /* Issue an unreg_login to all nodes on all vports */
1578 vports = lpfc_create_vport_work_array(phba);
1579 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001580 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001581 struct Scsi_Host *shost;
1582
James Smarta8adb832007-10-27 13:37:53 -04001583 if (vports[i]->load_flag & FC_UNLOADING)
1584 continue;
James Smart87af33f2007-10-27 13:37:43 -04001585 shost = lpfc_shost_from_vport(vports[i]);
1586 list_for_each_entry_safe(ndlp, next_ndlp,
1587 &vports[i]->fc_nodes,
1588 nlp_listp) {
1589 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1590 continue;
1591 if (ndlp->nlp_type & NLP_FABRIC) {
1592 lpfc_disc_state_machine(vports[i], ndlp,
1593 NULL, NLP_EVT_DEVICE_RECOVERY);
1594 lpfc_disc_state_machine(vports[i], ndlp,
1595 NULL, NLP_EVT_DEVICE_RM);
1596 }
1597 spin_lock_irq(shost->host_lock);
1598 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1599 spin_unlock_irq(shost->host_lock);
1600 lpfc_unreg_rpi(vports[i], ndlp);
1601 }
1602 }
1603 }
James Smart09372822008-01-11 01:52:54 -05001604 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001605
James Smart46fa3112007-04-25 09:51:45 -04001606 lpfc_sli_flush_mbox_queue(phba);
1607}
1608
1609void
James Smart2e0fef82007-06-17 19:56:36 -05001610lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001611{
James Smart549e55c2007-08-02 11:09:51 -04001612 struct Scsi_Host *shost;
1613 struct lpfc_vport **vports;
1614 int i;
James Smart46fa3112007-04-25 09:51:45 -04001615
James Smart549e55c2007-08-02 11:09:51 -04001616 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001617 return;
James Smart688a8862006-07-06 15:49:56 -04001618
dea31012005-04-17 16:05:31 -05001619 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001620 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001621 vports = lpfc_create_vport_work_array(phba);
1622 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001623 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04001624 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001625 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001626 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001627 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001628 /* Bring down the SLI Layer and cleanup. The HBA is offline
1629 now. */
1630 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001631 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001632 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001633 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001634 vports = lpfc_create_vport_work_array(phba);
1635 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001636 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001637 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04001638 spin_lock_irq(shost->host_lock);
1639 vports[i]->work_port_events = 0;
1640 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1641 spin_unlock_irq(shost->host_lock);
1642 }
James Smart09372822008-01-11 01:52:54 -05001643 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001644}
1645
1646/******************************************************************************
1647* Function name: lpfc_scsi_free
1648*
1649* Description: Called from lpfc_pci_remove_one free internal driver resources
1650*
1651******************************************************************************/
1652static int
James Smart2e0fef82007-06-17 19:56:36 -05001653lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001654{
1655 struct lpfc_scsi_buf *sb, *sb_next;
1656 struct lpfc_iocbq *io, *io_next;
1657
James Smart2e0fef82007-06-17 19:56:36 -05001658 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001659 /* Release all the lpfc_scsi_bufs maintained by this host. */
1660 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1661 list_del(&sb->list);
1662 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001663 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001664 kfree(sb);
1665 phba->total_scsi_bufs--;
1666 }
1667
1668 /* Release all the lpfc_iocbq entries maintained by this host. */
1669 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1670 list_del(&io->list);
1671 kfree(io);
1672 phba->total_iocbq_bufs--;
1673 }
1674
James Smart2e0fef82007-06-17 19:56:36 -05001675 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001676
1677 return 0;
1678}
1679
James Smart2e0fef82007-06-17 19:56:36 -05001680struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001681lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001682{
James Smart2e0fef82007-06-17 19:56:36 -05001683 struct lpfc_vport *vport;
1684 struct Scsi_Host *shost;
1685 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001686
James Smart3de2a652007-08-02 11:09:59 -04001687 if (dev != &phba->pcidev->dev)
1688 shost = scsi_host_alloc(&lpfc_vport_template,
1689 sizeof(struct lpfc_vport));
1690 else
1691 shost = scsi_host_alloc(&lpfc_template,
1692 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001693 if (!shost)
1694 goto out;
James Smart47a86172007-04-25 09:53:22 -04001695
James Smart2e0fef82007-06-17 19:56:36 -05001696 vport = (struct lpfc_vport *) shost->hostdata;
1697 vport->phba = phba;
James Smart47a86172007-04-25 09:53:22 -04001698
James Smart2e0fef82007-06-17 19:56:36 -05001699 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001700 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart47a86172007-04-25 09:53:22 -04001701
James Smart3de2a652007-08-02 11:09:59 -04001702 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001703 shost->unique_id = instance;
1704 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001705 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001706 shost->this_id = -1;
1707 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001708 /*
James Smart2e0fef82007-06-17 19:56:36 -05001709 * Set initial can_queue value since 0 is no longer supported and
1710 * scsi_add_host will fail. This will be adjusted later based on the
1711 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001712 */
James Smart2e0fef82007-06-17 19:56:36 -05001713 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001714 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001715 shost->transportt = lpfc_vport_transport_template;
1716 vport->port_type = LPFC_NPIV_PORT;
1717 } else {
1718 shost->transportt = lpfc_transport_template;
1719 vport->port_type = LPFC_PHYSICAL_PORT;
1720 }
James Smart47a86172007-04-25 09:53:22 -04001721
James Smart2e0fef82007-06-17 19:56:36 -05001722 /* Initialize all internally managed lists. */
1723 INIT_LIST_HEAD(&vport->fc_nodes);
1724 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001725
James Smart2e0fef82007-06-17 19:56:36 -05001726 init_timer(&vport->fc_disctmo);
1727 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001728 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001729
James Smart2e0fef82007-06-17 19:56:36 -05001730 init_timer(&vport->fc_fdmitmo);
1731 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001732 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001733
James Smart2e0fef82007-06-17 19:56:36 -05001734 init_timer(&vport->els_tmofunc);
1735 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001736 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001737
James Smart3de2a652007-08-02 11:09:59 -04001738 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001739 if (error)
1740 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001741
James Smart549e55c2007-08-02 11:09:51 -04001742 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001743 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001744 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001745 return vport;
James Smart47a86172007-04-25 09:53:22 -04001746
James Smart2e0fef82007-06-17 19:56:36 -05001747out_put_shost:
1748 scsi_host_put(shost);
1749out:
1750 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001751}
1752
James Smart2e0fef82007-06-17 19:56:36 -05001753void
1754destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001755{
James Smart92d7f7b2007-06-17 19:56:38 -05001756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1757 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001758
James Smart92d7f7b2007-06-17 19:56:38 -05001759 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001760
James Smart858c9f62007-06-17 19:56:39 -05001761 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001762 fc_remove_host(shost);
1763 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001764
James Smart92d7f7b2007-06-17 19:56:38 -05001765 spin_lock_irq(&phba->hbalock);
1766 list_del_init(&vport->listentry);
1767 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001768
James Smart92d7f7b2007-06-17 19:56:38 -05001769 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001770 return;
James Smart47a86172007-04-25 09:53:22 -04001771}
1772
James Smart92d7f7b2007-06-17 19:56:38 -05001773int
1774lpfc_get_instance(void)
1775{
1776 int instance = 0;
1777
1778 /* Assign an unused number */
1779 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1780 return -1;
1781 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1782 return -1;
1783 return instance;
1784}
1785
James Smart858c9f62007-06-17 19:56:39 -05001786/*
1787 * Note: there is no scan_start function as adapter initialization
1788 * will have asynchronously kicked off the link initialization.
1789 */
James Smart47a86172007-04-25 09:53:22 -04001790
1791int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1792{
James Smart2e0fef82007-06-17 19:56:36 -05001793 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1794 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001795 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001796
James Smart858c9f62007-06-17 19:56:39 -05001797 spin_lock_irq(shost->host_lock);
1798
James Smart51ef4c22007-08-02 11:10:31 -04001799 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05001800 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001801 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001802 }
James Smart2e0fef82007-06-17 19:56:36 -05001803 if (time >= 30 * HZ) {
1804 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001805 "0461 Scanning longer than 30 "
1806 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001807 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001808 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001809 }
1810 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1811 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001812 "0465 Link down longer than 15 "
1813 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001814 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001815 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001816 }
1817
James Smart2e0fef82007-06-17 19:56:36 -05001818 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001819 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001820 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001821 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001822 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001823 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001824 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001825 goto finished;
1826
1827 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001828
1829finished:
James Smart858c9f62007-06-17 19:56:39 -05001830 spin_unlock_irq(shost->host_lock);
1831 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001832}
1833
1834void lpfc_host_attrib_init(struct Scsi_Host *shost)
1835{
1836 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1837 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001838 /*
James Smart2e0fef82007-06-17 19:56:36 -05001839 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001840 */
1841
James Smart2e0fef82007-06-17 19:56:36 -05001842 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1843 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001844 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1845
1846 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001847 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001848 fc_host_supported_fc4s(shost)[2] = 1;
1849 fc_host_supported_fc4s(shost)[7] = 1;
1850
James Smart92d7f7b2007-06-17 19:56:38 -05001851 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1852 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001853
1854 fc_host_supported_speeds(shost) = 0;
1855 if (phba->lmt & LMT_10Gb)
1856 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04001857 if (phba->lmt & LMT_8Gb)
1858 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04001859 if (phba->lmt & LMT_4Gb)
1860 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1861 if (phba->lmt & LMT_2Gb)
1862 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1863 if (phba->lmt & LMT_1Gb)
1864 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1865
1866 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001867 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1868 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001869
1870 /* This value is also unchanging */
1871 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001872 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001873 fc_host_active_fc4s(shost)[2] = 1;
1874 fc_host_active_fc4s(shost)[7] = 1;
1875
James Smart92d7f7b2007-06-17 19:56:38 -05001876 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001877 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001878 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001879 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001880}
dea31012005-04-17 16:05:31 -05001881
1882static int __devinit
1883lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1884{
James Smart2e0fef82007-06-17 19:56:36 -05001885 struct lpfc_vport *vport = NULL;
1886 struct lpfc_hba *phba;
1887 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001888 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001889 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04001890 void *ptr;
dea31012005-04-17 16:05:31 -05001891 unsigned long bar0map_len, bar2map_len;
James Smart98c9ea52007-10-27 13:37:33 -04001892 int error = -ENODEV, retval;
James Smart51ef4c22007-08-02 11:10:31 -04001893 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05001894 uint16_t iotag;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001895 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
dea31012005-04-17 16:05:31 -05001896
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001897 if (pci_enable_device_bars(pdev, bars))
dea31012005-04-17 16:05:31 -05001898 goto out;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05001899 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
dea31012005-04-17 16:05:31 -05001900 goto out_disable_device;
1901
James Smart2e0fef82007-06-17 19:56:36 -05001902 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1903 if (!phba)
dea31012005-04-17 16:05:31 -05001904 goto out_release_regions;
1905
James Smart2e0fef82007-06-17 19:56:36 -05001906 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001907
dea31012005-04-17 16:05:31 -05001908 phba->pcidev = pdev;
1909
1910 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001911 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001912 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001913
James Smart2e0fef82007-06-17 19:56:36 -05001914 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05001915 /*
1916 * Get all the module params for configuring this host and then
1917 * establish the host.
1918 */
1919 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001920 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05001921
1922 /* Initialize timers used by driver */
1923 init_timer(&phba->fc_estabtmo);
1924 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1925 phba->fc_estabtmo.data = (unsigned long)phba;
dea31012005-04-17 16:05:31 -05001926
James Smart858c9f62007-06-17 19:56:39 -05001927 init_timer(&phba->hb_tmofunc);
1928 phba->hb_tmofunc.function = lpfc_hb_timeout;
1929 phba->hb_tmofunc.data = (unsigned long)phba;
1930
dea31012005-04-17 16:05:31 -05001931 psli = &phba->sli;
1932 init_timer(&psli->mbox_tmo);
1933 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001934 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001935 init_timer(&phba->fcp_poll_timer);
1936 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001937 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001938 init_timer(&phba->fabric_block_timer);
1939 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1940 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001941
dea31012005-04-17 16:05:31 -05001942 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07001943 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05001944
1945 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1946 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1947 goto out_idr_remove;
1948
1949 /*
1950 * Get the bus address of Bar0 and Bar2 and the number of bytes
1951 * required by each mapping.
1952 */
1953 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1954 bar0map_len = pci_resource_len(phba->pcidev, 0);
1955
1956 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1957 bar2map_len = pci_resource_len(phba->pcidev, 2);
1958
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001959 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001960 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001961 if (!phba->slim_memmap_p) {
1962 error = -ENODEV;
1963 dev_printk(KERN_ERR, &pdev->dev,
1964 "ioremap failed for SLIM memory.\n");
1965 goto out_idr_remove;
1966 }
1967
1968 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001969 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001970 if (!phba->ctrl_regs_memmap_p) {
1971 error = -ENODEV;
1972 dev_printk(KERN_ERR, &pdev->dev,
1973 "ioremap failed for HBA control registers.\n");
1974 goto out_iounmap_slim;
1975 }
dea31012005-04-17 16:05:31 -05001976
1977 /* Allocate memory for SLI-2 structures */
1978 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1979 &phba->slim2p_mapping, GFP_KERNEL);
1980 if (!phba->slim2p)
1981 goto out_iounmap;
1982
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001983 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05001984
James Smarted957682007-06-17 19:56:37 -05001985 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1986 lpfc_sli_hbq_size(),
1987 &phba->hbqslimp.phys,
1988 GFP_KERNEL);
1989 if (!phba->hbqslimp.virt)
1990 goto out_free_slim;
1991
James Smart51ef4c22007-08-02 11:10:31 -04001992 hbq_count = lpfc_sli_hbq_count();
1993 ptr = phba->hbqslimp.virt;
1994 for (i = 0; i < hbq_count; ++i) {
1995 phba->hbqs[i].hbq_virt = ptr;
1996 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
1997 ptr += (lpfc_hbq_defs[i]->entry_count *
1998 sizeof(struct lpfc_hbq_entry));
1999 }
2000 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2001 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2002
James Smarted957682007-06-17 19:56:37 -05002003 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2004
dea31012005-04-17 16:05:31 -05002005 /* Initialize the SLI Layer to run with lpfc HBAs. */
2006 lpfc_sli_setup(phba);
2007 lpfc_sli_queue_setup(phba);
2008
James Smart98c9ea52007-10-27 13:37:33 -04002009 retval = lpfc_mem_alloc(phba);
2010 if (retval) {
2011 error = retval;
James Smarted957682007-06-17 19:56:37 -05002012 goto out_free_hbqslimp;
James Smart98c9ea52007-10-27 13:37:33 -04002013 }
dea31012005-04-17 16:05:31 -05002014
2015 /* Initialize and populate the iocb list per host. */
2016 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2017 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002018 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002019 if (iocbq_entry == NULL) {
2020 printk(KERN_ERR "%s: only allocated %d iocbs of "
2021 "expected %d count. Unloading driver.\n",
2022 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
2023 error = -ENOMEM;
2024 goto out_free_iocbq;
2025 }
2026
James Bottomley604a3e32005-10-29 10:28:33 -05002027 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2028 if (iotag == 0) {
2029 kfree (iocbq_entry);
2030 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2031 "Unloading driver.\n",
2032 __FUNCTION__);
2033 error = -ENOMEM;
2034 goto out_free_iocbq;
2035 }
James Smart2e0fef82007-06-17 19:56:36 -05002036
2037 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002038 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2039 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002040 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002041 }
2042
2043 /* Initialize HBA structure */
2044 phba->fc_edtov = FF_DEF_EDTOV;
2045 phba->fc_ratov = FF_DEF_RATOV;
2046 phba->fc_altov = FF_DEF_ALTOV;
2047 phba->fc_arbtov = FF_DEF_ARBTOV;
2048
2049 INIT_LIST_HEAD(&phba->work_list);
2050 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2051 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2052
2053 /* Startup the kernel thread for this host adapter. */
2054 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2055 "lpfc_worker_%d", phba->brd_no);
2056 if (IS_ERR(phba->worker_thread)) {
2057 error = PTR_ERR(phba->worker_thread);
2058 goto out_free_iocbq;
2059 }
2060
dea31012005-04-17 16:05:31 -05002061 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002062 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05002063 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2064
James Smart92d7f7b2007-06-17 19:56:38 -05002065 /* Initialize list of fabric iocbs */
2066 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2067
James Smart0ff10d42008-01-11 01:52:36 -05002068 /* Initialize list to save ELS buffers */
2069 INIT_LIST_HEAD(&phba->elsbuf);
2070
James Smart3de2a652007-08-02 11:09:59 -04002071 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05002072 if (!vport)
2073 goto out_kthread_stop;
2074
2075 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002076 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002077 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002078
James Smart92d7f7b2007-06-17 19:56:38 -05002079 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05002080
James Smart4ff43242006-12-02 13:34:56 -05002081 if (phba->cfg_use_msi) {
James Smart98c9ea52007-10-27 13:37:33 -04002082 retval = pci_enable_msi(phba->pcidev);
2083 if (!retval)
James Smart51ef4c22007-08-02 11:10:31 -04002084 phba->using_msi = 1;
2085 else
James Smarte8b62012007-08-02 11:10:09 -04002086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2087 "0452 Enable MSI failed, continuing "
2088 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05002089 }
2090
James Smart98c9ea52007-10-27 13:37:33 -04002091 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
James Smart2e0fef82007-06-17 19:56:36 -05002092 LPFC_DRIVER_NAME, phba);
James Smart98c9ea52007-10-27 13:37:33 -04002093 if (retval) {
dea31012005-04-17 16:05:31 -05002094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002095 "0451 Enable interrupt handler failed\n");
James Smart98c9ea52007-10-27 13:37:33 -04002096 error = retval;
James Smart92d7f7b2007-06-17 19:56:38 -05002097 goto out_disable_msi;
dea31012005-04-17 16:05:31 -05002098 }
dea31012005-04-17 16:05:31 -05002099
James Smart2e0fef82007-06-17 19:56:36 -05002100 phba->MBslimaddr = phba->slim_memmap_p;
2101 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2102 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2103 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2104 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2105
James Smart98c9ea52007-10-27 13:37:33 -04002106 if (lpfc_alloc_sysfs_attr(vport)) {
2107 error = -ENOMEM;
dea31012005-04-17 16:05:31 -05002108 goto out_free_irq;
James Smart98c9ea52007-10-27 13:37:33 -04002109 }
dea31012005-04-17 16:05:31 -05002110
James Smart98c9ea52007-10-27 13:37:33 -04002111 if (lpfc_sli_hba_setup(phba)) {
2112 error = -ENODEV;
James Smart858c9f62007-06-17 19:56:39 -05002113 goto out_remove_device;
James Smart98c9ea52007-10-27 13:37:33 -04002114 }
James Smart858c9f62007-06-17 19:56:39 -05002115
2116 /*
2117 * hba setup may have changed the hba_queue_depth so we need to adjust
2118 * the value of can_queue.
2119 */
2120 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2121
2122 lpfc_host_attrib_init(shost);
2123
James Smart2e0fef82007-06-17 19:56:36 -05002124 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2125 spin_lock_irq(shost->host_lock);
2126 lpfc_poll_start_timer(phba);
2127 spin_unlock_irq(shost->host_lock);
2128 }
James Smart8f6d98d2006-08-01 07:34:00 -04002129
James Smart858c9f62007-06-17 19:56:39 -05002130 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05002131
dea31012005-04-17 16:05:31 -05002132 return 0;
2133
James Smart858c9f62007-06-17 19:56:39 -05002134out_remove_device:
2135 lpfc_free_sysfs_attr(vport);
2136 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002137 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05002138 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002139out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05002140 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002141 phba->pport->work_port_events = 0;
dea31012005-04-17 16:05:31 -05002142 free_irq(phba->pcidev->irq, phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002143out_disable_msi:
James Smart51ef4c22007-08-02 11:10:31 -04002144 if (phba->using_msi)
2145 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05002146 destroy_port(vport);
dea31012005-04-17 16:05:31 -05002147out_kthread_stop:
2148 kthread_stop(phba->worker_thread);
2149out_free_iocbq:
2150 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2151 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05002152 kfree(iocbq_entry);
2153 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05002154 }
2155 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05002156out_free_hbqslimp:
2157 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2158 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05002159out_free_slim:
2160 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
2161 phba->slim2p_mapping);
2162out_iounmap:
2163 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002164out_iounmap_slim:
dea31012005-04-17 16:05:31 -05002165 iounmap(phba->slim_memmap_p);
2166out_idr_remove:
2167 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002168out_free_phba:
2169 kfree(phba);
dea31012005-04-17 16:05:31 -05002170out_release_regions:
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002171 pci_release_selected_regions(pdev, bars);
dea31012005-04-17 16:05:31 -05002172out_disable_device:
2173 pci_disable_device(pdev);
2174out:
James Smartdefbcf12006-04-16 22:26:50 -04002175 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002176 if (shost)
2177 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05002178 return error;
2179}
2180
2181static void __devexit
2182lpfc_pci_remove_one(struct pci_dev *pdev)
2183{
James Smart2e0fef82007-06-17 19:56:36 -05002184 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2186 struct lpfc_hba *phba = vport->phba;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002187 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2188
James Smart549e55c2007-08-02 11:09:51 -04002189 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002190 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002191 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002192
James Smart858c9f62007-06-17 19:56:39 -05002193 kfree(vport->vname);
2194 lpfc_free_sysfs_attr(vport);
2195
James Smart09372822008-01-11 01:52:54 -05002196 kthread_stop(phba->worker_thread);
2197
James Smart858c9f62007-06-17 19:56:39 -05002198 fc_remove_host(shost);
2199 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04002200 lpfc_cleanup(vport);
2201
James Smart2e0fef82007-06-17 19:56:36 -05002202 /*
2203 * Bring down the SLI Layer. This step disable all interrupts,
2204 * clears the rings, discards all mailbox commands, and resets
2205 * the HBA.
2206 */
2207 lpfc_sli_hba_down(phba);
2208 lpfc_sli_brdrestart(phba);
2209
James Smart92d7f7b2007-06-17 19:56:38 -05002210 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002211 spin_lock_irq(&phba->hbalock);
2212 list_del_init(&vport->listentry);
2213 spin_unlock_irq(&phba->hbalock);
2214
James Smart858c9f62007-06-17 19:56:39 -05002215 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002216
James Smart2e0fef82007-06-17 19:56:36 -05002217 /* Release the irq reservation */
2218 free_irq(phba->pcidev->irq, phba);
James Smart51ef4c22007-08-02 11:10:31 -04002219 if (phba->using_msi)
2220 pci_disable_msi(phba->pcidev);
dea31012005-04-17 16:05:31 -05002221
2222 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002223 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002224
2225 /*
2226 * Call scsi_free before mem_free since scsi bufs are released to their
2227 * corresponding pools here.
2228 */
2229 lpfc_scsi_free(phba);
2230 lpfc_mem_free(phba);
2231
James Smarted957682007-06-17 19:56:37 -05002232 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2233 phba->hbqslimp.phys);
2234
James Smart2e0fef82007-06-17 19:56:36 -05002235 /* Free resources associated with SLI2 interface */
2236 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2237 phba->slim2p, phba->slim2p_mapping);
2238
2239 /* unmap adapter SLIM and Control Registers */
2240 iounmap(phba->ctrl_regs_memmap_p);
2241 iounmap(phba->slim_memmap_p);
2242
2243 idr_remove(&lpfc_hba_index, phba->brd_no);
2244
2245 kfree(phba);
2246
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05002247 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05002248 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002249}
2250
Linas Vepstas8d63f372007-02-14 14:28:36 -06002251/**
2252 * lpfc_io_error_detected - called when PCI error is detected
2253 * @pdev: Pointer to PCI device
2254 * @state: The current pci conneection state
2255 *
2256 * This function is called after a PCI bus error affecting
2257 * this device has been detected.
2258 */
2259static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2260 pci_channel_state_t state)
2261{
James Smart51ef4c22007-08-02 11:10:31 -04002262 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2263 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002264 struct lpfc_sli *psli = &phba->sli;
2265 struct lpfc_sli_ring *pring;
2266
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002267 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002268 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002269
Linas Vepstas8d63f372007-02-14 14:28:36 -06002270 pci_disable_device(pdev);
2271 /*
2272 * There may be I/Os dropped by the firmware.
2273 * Error iocb (I/O) on txcmplq and let the SCSI layer
2274 * retry it after re-establishing link.
2275 */
2276 pring = &psli->ring[psli->fcp_ring];
2277 lpfc_sli_abort_iocb_ring(phba, pring);
2278
James Smart51ef4c22007-08-02 11:10:31 -04002279 /* Release the irq reservation */
2280 free_irq(phba->pcidev->irq, phba);
2281 if (phba->using_msi)
2282 pci_disable_msi(phba->pcidev);
2283
Linas Vepstas8d63f372007-02-14 14:28:36 -06002284 /* Request a slot reset. */
2285 return PCI_ERS_RESULT_NEED_RESET;
2286}
2287
2288/**
2289 * lpfc_io_slot_reset - called after the pci bus has been reset.
2290 * @pdev: Pointer to PCI device
2291 *
2292 * Restart the card from scratch, as if from a cold-boot.
2293 */
2294static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2295{
James Smart51ef4c22007-08-02 11:10:31 -04002296 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2297 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002298 struct lpfc_sli *psli = &phba->sli;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002299
2300 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002301 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06002302 printk(KERN_ERR "lpfc: Cannot re-enable "
2303 "PCI device after reset.\n");
2304 return PCI_ERS_RESULT_DISCONNECT;
2305 }
2306
2307 pci_set_master(pdev);
2308
2309 /* Re-establishing Link */
James Smart51ef4c22007-08-02 11:10:31 -04002310 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002311 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart51ef4c22007-08-02 11:10:31 -04002312 spin_unlock_irq(shost->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002313
James Smart92d7f7b2007-06-17 19:56:38 -05002314 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002315 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002316 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002317
2318
2319 /* Take device offline; this will perform cleanup */
2320 lpfc_offline(phba);
2321 lpfc_sli_brdrestart(phba);
2322
2323 return PCI_ERS_RESULT_RECOVERED;
2324}
2325
2326/**
2327 * lpfc_io_resume - called when traffic can start flowing again.
2328 * @pdev: Pointer to PCI device
2329 *
2330 * This callback is called when the error recovery driver tells us that
2331 * its OK to resume normal operation.
2332 */
2333static void lpfc_io_resume(struct pci_dev *pdev)
2334{
James Smart51ef4c22007-08-02 11:10:31 -04002335 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2336 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002337
2338 if (lpfc_online(phba) == 0) {
2339 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2340 }
2341}
2342
dea31012005-04-17 16:05:31 -05002343static struct pci_device_id lpfc_id_table[] = {
2344 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2345 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002346 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2347 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002348 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2349 PCI_ANY_ID, PCI_ANY_ID, },
2350 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2351 PCI_ANY_ID, PCI_ANY_ID, },
2352 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2353 PCI_ANY_ID, PCI_ANY_ID, },
2354 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2355 PCI_ANY_ID, PCI_ANY_ID, },
2356 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2357 PCI_ANY_ID, PCI_ANY_ID, },
2358 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2359 PCI_ANY_ID, PCI_ANY_ID, },
2360 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2361 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002362 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2363 PCI_ANY_ID, PCI_ANY_ID, },
2364 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2365 PCI_ANY_ID, PCI_ANY_ID, },
2366 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2367 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002368 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2369 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002370 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2371 PCI_ANY_ID, PCI_ANY_ID, },
2372 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2373 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002374 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2375 PCI_ANY_ID, PCI_ANY_ID, },
2376 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2377 PCI_ANY_ID, PCI_ANY_ID, },
2378 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2379 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002380 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2381 PCI_ANY_ID, PCI_ANY_ID, },
2382 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2383 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002384 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2385 PCI_ANY_ID, PCI_ANY_ID, },
2386 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2387 PCI_ANY_ID, PCI_ANY_ID, },
2388 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2389 PCI_ANY_ID, PCI_ANY_ID, },
2390 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2391 PCI_ANY_ID, PCI_ANY_ID, },
2392 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2393 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002394 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2395 PCI_ANY_ID, PCI_ANY_ID, },
2396 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2397 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002398 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2399 PCI_ANY_ID, PCI_ANY_ID, },
2400 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2401 PCI_ANY_ID, PCI_ANY_ID, },
2402 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2403 PCI_ANY_ID, PCI_ANY_ID, },
2404 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2405 PCI_ANY_ID, PCI_ANY_ID, },
2406 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2407 PCI_ANY_ID, PCI_ANY_ID, },
2408 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2409 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002410 { 0 }
2411};
2412
2413MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2414
Linas Vepstas8d63f372007-02-14 14:28:36 -06002415static struct pci_error_handlers lpfc_err_handler = {
2416 .error_detected = lpfc_io_error_detected,
2417 .slot_reset = lpfc_io_slot_reset,
2418 .resume = lpfc_io_resume,
2419};
2420
dea31012005-04-17 16:05:31 -05002421static struct pci_driver lpfc_driver = {
2422 .name = LPFC_DRIVER_NAME,
2423 .id_table = lpfc_id_table,
2424 .probe = lpfc_pci_probe_one,
2425 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002426 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002427};
2428
2429static int __init
2430lpfc_init(void)
2431{
2432 int error = 0;
2433
2434 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002435 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002436
James Smart7ee5d432007-10-27 13:37:17 -04002437 if (lpfc_enable_npiv) {
2438 lpfc_transport_functions.vport_create = lpfc_vport_create;
2439 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2440 }
dea31012005-04-17 16:05:31 -05002441 lpfc_transport_template =
2442 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04002443 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05002444 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04002445 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04002446 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04002447 fc_attach_transport(&lpfc_vport_transport_functions);
2448 if (lpfc_vport_transport_template == NULL) {
2449 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002450 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04002451 }
James Smart7ee5d432007-10-27 13:37:17 -04002452 }
dea31012005-04-17 16:05:31 -05002453 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002454 if (error) {
dea31012005-04-17 16:05:31 -05002455 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002456 fc_release_transport(lpfc_vport_transport_template);
2457 }
dea31012005-04-17 16:05:31 -05002458
2459 return error;
2460}
2461
2462static void __exit
2463lpfc_exit(void)
2464{
2465 pci_unregister_driver(&lpfc_driver);
2466 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04002467 if (lpfc_enable_npiv)
2468 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002469}
2470
2471module_init(lpfc_init);
2472module_exit(lpfc_exit);
2473MODULE_LICENSE("GPL");
2474MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2475MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2476MODULE_VERSION("0:" LPFC_DRIVER_VERSION);