blob: 21f8f7a56e23aaba59f75ae66bbd06b8b11617d3 [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"
James Smart92d7f7b2007-06-17 19:56:38 -050046#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050047
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050048static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050049static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
50static int lpfc_post_rcv_buf(struct lpfc_hba *);
51
52static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050053static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050054static DEFINE_IDR(lpfc_hba_index);
55
James Smart2e0fef82007-06-17 19:56:36 -050056
57
James Smart51ef4c22007-08-02 11:10:31 -040058extern struct lpfc_hbq_init *lpfc_hbq_defs[];
59
dea31012005-04-17 16:05:31 -050060/************************************************************************/
61/* */
62/* lpfc_config_port_prep */
63/* This routine will do LPFC initialization prior to the */
64/* CONFIG_PORT mailbox command. This will be initialized */
65/* as a SLI layer callback routine. */
66/* This routine returns 0 on success or -ERESTART if it wants */
67/* the SLI layer to reset the HBA and try again. Any */
68/* other return value indicates an error. */
69/* */
70/************************************************************************/
71int
James Smart2e0fef82007-06-17 19:56:36 -050072lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050073{
74 lpfc_vpd_t *vp = &phba->vpd;
75 int i = 0, rc;
76 LPFC_MBOXQ_t *pmb;
77 MAILBOX_t *mb;
78 char *lpfc_vpd_data = NULL;
79 uint16_t offset = 0;
80 static char licensed[56] =
81 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040082 static int init_key = 1;
dea31012005-04-17 16:05:31 -050083
84 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
85 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050086 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050087 return -ENOMEM;
88 }
89
90 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050091 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050092
93 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040094 if (init_key) {
95 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050096
James Smart65a29c12006-07-06 15:50:50 -040097 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
98 *ptext = cpu_to_be32(*ptext);
99 init_key = 0;
100 }
dea31012005-04-17 16:05:31 -0500101
102 lpfc_read_nv(phba, pmb);
103 memset((char*)mb->un.varRDnvp.rsvd3, 0,
104 sizeof (mb->un.varRDnvp.rsvd3));
105 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
106 sizeof (licensed));
107
108 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
109
110 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500111 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400112 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500113 "error, mbxCmd x%x READ_NVPARM, "
114 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500115 mb->mbxCommand, mb->mbxStatus);
116 mempool_free(pmb, phba->mbox_mem_pool);
117 return -ERESTART;
118 }
119 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500120 sizeof(phba->wwnn));
121 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
122 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500123 }
124
James Smart92d7f7b2007-06-17 19:56:38 -0500125 phba->sli3_options = 0x0;
126
dea31012005-04-17 16:05:31 -0500127 /* Setup and issue mailbox READ REV command */
128 lpfc_read_rev(phba, pmb);
129 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
130 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400132 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500133 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500134 mb->mbxCommand, mb->mbxStatus);
135 mempool_free( pmb, phba->mbox_mem_pool);
136 return -ERESTART;
137 }
138
James Smart92d7f7b2007-06-17 19:56:38 -0500139
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500140 /*
141 * The value of rr must be 1 since the driver set the cv field to 1.
142 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500143 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500144 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500145 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400147 "0440 Adapter failed to init, READ_REV has "
148 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500149 mempool_free(pmb, phba->mbox_mem_pool);
150 return -ERESTART;
dea31012005-04-17 16:05:31 -0500151 }
152
James Smarted957682007-06-17 19:56:37 -0500153 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
154 return -EINVAL;
155
dea31012005-04-17 16:05:31 -0500156 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500157 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500158 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500159 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
160 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
161 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
162 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500163 vp->rev.biuRev = mb->un.varRdRev.biuRev;
164 vp->rev.smRev = mb->un.varRdRev.smRev;
165 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
166 vp->rev.endecRev = mb->un.varRdRev.endecRev;
167 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
168 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
169 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
170 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
171 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
172 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
173
James Smart92d7f7b2007-06-17 19:56:38 -0500174 /* If the sli feature level is less then 9, we must
175 * tear down all RPIs and VPIs on link down if NPIV
176 * is enabled.
177 */
178 if (vp->rev.feaLevelHigh < 9)
179 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
180
dea31012005-04-17 16:05:31 -0500181 if (lpfc_is_LC_HBA(phba->pcidev->device))
182 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
183 sizeof (phba->RandomData));
184
dea31012005-04-17 16:05:31 -0500185 /* Get adapter VPD information */
186 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
187 if (!pmb->context2)
188 goto out_free_mbox;
189 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
190 if (!lpfc_vpd_data)
191 goto out_free_context2;
192
193 do {
194 lpfc_dump_mem(phba, pmb, offset);
195 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
196
197 if (rc != MBX_SUCCESS) {
198 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400199 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500200 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500201 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500202 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500203 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500204 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
205 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
dea31012005-04-17 16:05:31 -0500206 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500207 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500208 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500209 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
210 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500211
212 kfree(lpfc_vpd_data);
213out_free_context2:
214 kfree(pmb->context2);
215out_free_mbox:
216 mempool_free(pmb, phba->mbox_mem_pool);
217 return 0;
218}
219
220/************************************************************************/
221/* */
222/* lpfc_config_port_post */
223/* This routine will do LPFC initialization after the */
224/* CONFIG_PORT mailbox command. This will be initialized */
225/* as a SLI layer callback routine. */
226/* This routine returns 0 on success. Any other return value */
227/* indicates an error. */
228/* */
229/************************************************************************/
230int
James Smart2e0fef82007-06-17 19:56:36 -0500231lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500232{
James Smart2e0fef82007-06-17 19:56:36 -0500233 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500234 LPFC_MBOXQ_t *pmb;
235 MAILBOX_t *mb;
236 struct lpfc_dmabuf *mp;
237 struct lpfc_sli *psli = &phba->sli;
238 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500239 int i, j;
240 int rc;
dea31012005-04-17 16:05:31 -0500241
242 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
243 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500244 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500245 return -ENOMEM;
246 }
247 mb = &pmb->mb;
248
dea31012005-04-17 16:05:31 -0500249 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500250 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500251 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500252 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400254 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500255 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500256 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500257 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500258 mp = (struct lpfc_dmabuf *) pmb->context1;
259 mempool_free( pmb, phba->mbox_mem_pool);
260 lpfc_mbuf_free(phba, mp->virt, mp->phys);
261 kfree(mp);
262 return -EIO;
263 }
264
265 mp = (struct lpfc_dmabuf *) pmb->context1;
266
James Smart2e0fef82007-06-17 19:56:36 -0500267 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500268 lpfc_mbuf_free(phba, mp->virt, mp->phys);
269 kfree(mp);
270 pmb->context1 = NULL;
271
James Smarta12e07b2006-12-02 13:35:30 -0500272 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500273 u64_to_wwn(phba->cfg_soft_wwnn,
274 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400275 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500276 u64_to_wwn(phba->cfg_soft_wwpn,
277 vport->fc_sparam.portName.u.wwn);
278 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500279 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500280 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500281 sizeof (struct lpfc_name));
282 /* If no serial number in VPD data, use low 6 bytes of WWNN */
283 /* This should be consolidated into parse_vpd ? - mr */
284 if (phba->SerialNumber[0] == 0) {
285 uint8_t *outptr;
286
James Smart2e0fef82007-06-17 19:56:36 -0500287 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500288 for (i = 0; i < 12; i++) {
289 status = *outptr++;
290 j = ((status & 0xf0) >> 4);
291 if (j <= 9)
292 phba->SerialNumber[i] =
293 (char)((uint8_t) 0x30 + (uint8_t) j);
294 else
295 phba->SerialNumber[i] =
296 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
297 i++;
298 j = (status & 0xf);
299 if (j <= 9)
300 phba->SerialNumber[i] =
301 (char)((uint8_t) 0x30 + (uint8_t) j);
302 else
303 phba->SerialNumber[i] =
304 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
305 }
306 }
307
dea31012005-04-17 16:05:31 -0500308 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500309 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500310 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400312 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500313 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500314 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500315 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500316 mempool_free( pmb, phba->mbox_mem_pool);
317 return -EIO;
318 }
319
320 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
321 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
322 phba->cfg_hba_queue_depth =
323 mb->un.varRdConfig.max_xri + 1;
324
325 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500326
327 /* Get the default values for Model Name and Description */
328 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
329
330 if ((phba->cfg_link_speed > LINK_SPEED_10G)
331 || ((phba->cfg_link_speed == LINK_SPEED_1G)
332 && !(phba->lmt & LMT_1Gb))
333 || ((phba->cfg_link_speed == LINK_SPEED_2G)
334 && !(phba->lmt & LMT_2Gb))
335 || ((phba->cfg_link_speed == LINK_SPEED_4G)
336 && !(phba->lmt & LMT_4Gb))
337 || ((phba->cfg_link_speed == LINK_SPEED_8G)
338 && !(phba->lmt & LMT_8Gb))
339 || ((phba->cfg_link_speed == LINK_SPEED_10G)
340 && !(phba->lmt & LMT_10Gb))) {
341 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500342 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400343 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500344 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500345 phba->cfg_link_speed);
346 phba->cfg_link_speed = LINK_SPEED_AUTO;
347 }
348
James Smart2e0fef82007-06-17 19:56:36 -0500349 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500350
351 /* Only process IOCBs on ring 0 till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500352 if (psli->ring[psli->extra_ring].cmdringaddr)
353 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500354 if (psli->ring[psli->fcp_ring].cmdringaddr)
355 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
356 if (psli->ring[psli->next_ring].cmdringaddr)
357 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
358
359 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500360 if (phba->sli_rev != 3)
361 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500362
363 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500364 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500365 status = readl(phba->HCregaddr);
366 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
367 if (psli->num_rings > 0)
368 status |= HC_R0INT_ENA;
369 if (psli->num_rings > 1)
370 status |= HC_R1INT_ENA;
371 if (psli->num_rings > 2)
372 status |= HC_R2INT_ENA;
373 if (psli->num_rings > 3)
374 status |= HC_R3INT_ENA;
375
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500376 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
377 (phba->cfg_poll & DISABLE_FCP_RING_INT))
378 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
379
dea31012005-04-17 16:05:31 -0500380 writel(status, phba->HCregaddr);
381 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500382 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500383
384 /*
385 * Setup the ring 0 (els) timeout handler
386 */
387 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500388 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500389 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
390 phba->hb_outstanding = 0;
391 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500392
393 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
394 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500395 pmb->vport = vport;
James Smart8aee9182006-08-31 12:27:57 -0400396 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400397 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400398 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400400 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500401 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500402 mb->mbxCommand, mb->mbxStatus);
403
404 /* Clear all interrupt enable conditions */
405 writel(0, phba->HCregaddr);
406 readl(phba->HCregaddr); /* flush */
407 /* Clear all pending interrupts */
408 writel(0xffffffff, phba->HAregaddr);
409 readl(phba->HAregaddr); /* flush */
410
James Smart2e0fef82007-06-17 19:56:36 -0500411 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400412 if (rc != MBX_BUSY)
413 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500414 return -EIO;
415 }
416 /* MBOX buffer will be freed in mbox compl */
417
James Smartce8b3ce2006-07-06 15:50:36 -0400418 return (0);
419}
420
dea31012005-04-17 16:05:31 -0500421/************************************************************************/
422/* */
423/* lpfc_hba_down_prep */
424/* This routine will do LPFC uninitialization before the */
425/* HBA is reset when bringing down the SLI Layer. This will be */
426/* initialized as a SLI layer callback routine. */
427/* This routine returns 0 on success. Any other return value */
428/* indicates an error. */
429/* */
430/************************************************************************/
431int
James Smart2e0fef82007-06-17 19:56:36 -0500432lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500433{
434 /* Disable interrupts */
435 writel(0, phba->HCregaddr);
436 readl(phba->HCregaddr); /* flush */
437
James Smart51ef4c22007-08-02 11:10:31 -0400438 lpfc_cleanup_discovery_resources(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -0500439 return 0;
dea31012005-04-17 16:05:31 -0500440}
441
442/************************************************************************/
443/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500444/* lpfc_hba_down_post */
445/* This routine will do uninitialization after the HBA is reset */
446/* when bringing down the SLI Layer. */
447/* This routine returns 0 on success. Any other return value */
448/* indicates an error. */
449/* */
450/************************************************************************/
451int
James Smart2e0fef82007-06-17 19:56:36 -0500452lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500453{
454 struct lpfc_sli *psli = &phba->sli;
455 struct lpfc_sli_ring *pring;
456 struct lpfc_dmabuf *mp, *next_mp;
457 int i;
458
James Smart92d7f7b2007-06-17 19:56:38 -0500459 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
460 lpfc_sli_hbqbuf_free_all(phba);
461 else {
462 /* Cleanup preposted buffers on the ELS ring */
463 pring = &psli->ring[LPFC_ELS_RING];
464 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
465 list_del(&mp->list);
466 pring->postbufq_cnt--;
467 lpfc_mbuf_free(phba, mp->virt, mp->phys);
468 kfree(mp);
469 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500470 }
471
472 for (i = 0; i < psli->num_rings; i++) {
473 pring = &psli->ring[i];
474 lpfc_sli_abort_iocb_ring(phba, pring);
475 }
476
477 return 0;
478}
479
James Smart858c9f62007-06-17 19:56:39 -0500480/* HBA heart beat timeout handler */
481void
482lpfc_hb_timeout(unsigned long ptr)
483{
484 struct lpfc_hba *phba;
485 unsigned long iflag;
486
487 phba = (struct lpfc_hba *)ptr;
488 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
489 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
490 phba->pport->work_port_events |= WORKER_HB_TMO;
491 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
492
493 if (phba->work_wait)
494 wake_up(phba->work_wait);
495 return;
496}
497
498static void
499lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
500{
501 unsigned long drvr_flag;
502
503 spin_lock_irqsave(&phba->hbalock, drvr_flag);
504 phba->hb_outstanding = 0;
505 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
506
507 mempool_free(pmboxq, phba->mbox_mem_pool);
508 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
509 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400510 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500511 mod_timer(&phba->hb_tmofunc,
512 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
513 return;
514}
515
516void
517lpfc_hb_timeout_handler(struct lpfc_hba *phba)
518{
519 LPFC_MBOXQ_t *pmboxq;
520 int retval;
521 struct lpfc_sli *psli = &phba->sli;
522
523 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400524 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500525 (phba->pport->fc_flag & FC_OFFLINE_MODE))
526 return;
527
528 spin_lock_irq(&phba->pport->work_port_lock);
529 /* If the timer is already canceled do nothing */
530 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
531 spin_unlock_irq(&phba->pport->work_port_lock);
532 return;
533 }
534
535 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
536 jiffies)) {
537 spin_unlock_irq(&phba->pport->work_port_lock);
538 if (!phba->hb_outstanding)
539 mod_timer(&phba->hb_tmofunc,
540 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
541 else
542 mod_timer(&phba->hb_tmofunc,
543 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
544 return;
545 }
546 spin_unlock_irq(&phba->pport->work_port_lock);
547
548 /* If there is no heart beat outstanding, issue a heartbeat command */
549 if (!phba->hb_outstanding) {
550 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
551 if (!pmboxq) {
552 mod_timer(&phba->hb_tmofunc,
553 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
554 return;
555 }
556
557 lpfc_heart_beat(phba, pmboxq);
558 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
559 pmboxq->vport = phba->pport;
560 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
561
562 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
563 mempool_free(pmboxq, phba->mbox_mem_pool);
564 mod_timer(&phba->hb_tmofunc,
565 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
566 return;
567 }
568 mod_timer(&phba->hb_tmofunc,
569 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
570 phba->hb_outstanding = 1;
571 return;
572 } else {
573 /*
574 * If heart beat timeout called with hb_outstanding set we
575 * need to take the HBA offline.
576 */
577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400578 "0459 Adapter heartbeat failure, taking "
579 "this port offline.\n");
James Smart858c9f62007-06-17 19:56:39 -0500580
581 spin_lock_irq(&phba->hbalock);
582 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
583 spin_unlock_irq(&phba->hbalock);
584
585 lpfc_offline_prep(phba);
586 lpfc_offline(phba);
587 lpfc_unblock_mgmt_io(phba);
588 phba->link_state = LPFC_HBA_ERROR;
589 lpfc_hba_down_post(phba);
590 }
591}
592
Jamie Wellnitz41415862006-02-28 19:25:27 -0500593/************************************************************************/
594/* */
dea31012005-04-17 16:05:31 -0500595/* lpfc_handle_eratt */
596/* This routine will handle processing a Host Attention */
597/* Error Status event. This will be initialized */
598/* as a SLI layer callback routine. */
599/* */
600/************************************************************************/
601void
James Smart2e0fef82007-06-17 19:56:36 -0500602lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500603{
James Smart2e0fef82007-06-17 19:56:36 -0500604 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500605 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500606 struct lpfc_sli_ring *pring;
James Smart549e55c2007-08-02 11:09:51 -0400607 struct lpfc_vport **vports;
James Smartd2873e42006-08-18 17:46:43 -0400608 uint32_t event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500609 struct Scsi_Host *shost;
James Smart549e55c2007-08-02 11:09:51 -0400610 int i;
James Smart2e0fef82007-06-17 19:56:36 -0500611
Linas Vepstas8d63f372007-02-14 14:28:36 -0600612 /* If the pci channel is offline, ignore possible errors,
613 * since we cannot communicate with the pci card anyway. */
614 if (pci_channel_offline(phba->pcidev))
615 return;
dea31012005-04-17 16:05:31 -0500616
James Smartf5603512006-12-02 13:35:43 -0500617 if (phba->work_hs & HS_FFER6 ||
618 phba->work_hs & HS_FFER5) {
dea31012005-04-17 16:05:31 -0500619 /* Re-establishing Link */
620 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400621 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500622 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400623 phba->work_hs,
dea31012005-04-17 16:05:31 -0500624 phba->work_status[0], phba->work_status[1]);
James Smart549e55c2007-08-02 11:09:51 -0400625 vports = lpfc_create_vport_work_array(phba);
626 if (vports != NULL)
627 for(i = 0;
628 i < LPFC_MAX_VPORTS && vports[i] != NULL;
629 i++){
630 shost = lpfc_shost_from_vport(vports[i]);
631 spin_lock_irq(shost->host_lock);
632 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
633 spin_unlock_irq(shost->host_lock);
634 }
635 lpfc_destroy_vport_work_array(vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500636 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500637 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500638 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500639
640 /*
641 * Firmware stops when it triggled erratt with HS_FFER6.
642 * That could cause the I/Os dropped by the firmware.
643 * Error iocb (I/O) on txcmplq and let the SCSI layer
644 * retry it after re-establishing link.
645 */
646 pring = &psli->ring[psli->fcp_ring];
647 lpfc_sli_abort_iocb_ring(phba, pring);
648
649
650 /*
651 * There was a firmware error. Take the hba offline and then
652 * attempt to restart it.
653 */
James Smart46fa3112007-04-25 09:51:45 -0400654 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500655 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500656 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500657 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
658 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
James Smart46fa3112007-04-25 09:51:45 -0400659 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500660 return;
661 }
James Smart46fa3112007-04-25 09:51:45 -0400662 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500663 } else {
664 /* The if clause above forces this code path when the status
665 * failure is a value other than FFER6. Do not call the offline
666 * twice. This is the adapter hardware error path.
667 */
668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400669 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -0500670 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400671 phba->work_hs,
dea31012005-04-17 16:05:31 -0500672 phba->work_status[0], phba->work_status[1]);
673
James Smartd2873e42006-08-18 17:46:43 -0400674 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500675 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500676 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400677 sizeof(event_data), (char *) &event_data,
678 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
679
James Smart92d7f7b2007-06-17 19:56:38 -0500680 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500681 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500682 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -0400683 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500684 lpfc_offline(phba);
James Smart46fa3112007-04-25 09:51:45 -0400685 lpfc_unblock_mgmt_io(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500686 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500687 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -0500688 }
689}
690
691/************************************************************************/
692/* */
693/* lpfc_handle_latt */
694/* This routine will handle processing a Host Attention */
695/* Link Status event. This will be initialized */
696/* as a SLI layer callback routine. */
697/* */
698/************************************************************************/
699void
James Smart2e0fef82007-06-17 19:56:36 -0500700lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500701{
James Smart2e0fef82007-06-17 19:56:36 -0500702 struct lpfc_vport *vport = phba->pport;
703 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500704 LPFC_MBOXQ_t *pmb;
705 volatile uint32_t control;
706 struct lpfc_dmabuf *mp;
707 int rc = -ENOMEM;
708
709 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
710 if (!pmb)
711 goto lpfc_handle_latt_err_exit;
712
713 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
714 if (!mp)
715 goto lpfc_handle_latt_free_pmb;
716
717 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
718 if (!mp->virt)
719 goto lpfc_handle_latt_free_mp;
720
721 rc = -EIO;
722
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500723 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400724 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500725
726 psli->slistat.link_event++;
727 lpfc_read_la(phba, pmb, mp);
728 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500729 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500730 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
731 if (rc == MBX_NOT_FINISHED)
James Smart14691152006-12-02 13:34:28 -0500732 goto lpfc_handle_latt_free_mbuf;
dea31012005-04-17 16:05:31 -0500733
734 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500735 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500736 writel(HA_LATT, phba->HAregaddr);
737 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500738 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500739
740 return;
741
James Smart14691152006-12-02 13:34:28 -0500742lpfc_handle_latt_free_mbuf:
743 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500744lpfc_handle_latt_free_mp:
745 kfree(mp);
746lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400747 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500748lpfc_handle_latt_err_exit:
749 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500750 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500751 psli->sli_flag |= LPFC_PROCESS_LA;
752 control = readl(phba->HCregaddr);
753 control |= HC_LAINT_ENA;
754 writel(control, phba->HCregaddr);
755 readl(phba->HCregaddr); /* flush */
756
757 /* Clear Link Attention in HA REG */
758 writel(HA_LATT, phba->HAregaddr);
759 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500760 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500761 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500762 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500763
764 /* The other case is an error from issue_mbox */
765 if (rc == -ENOMEM)
James Smarted957682007-06-17 19:56:37 -0500766 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400767 "0300 READ_LA: no buffers\n");
dea31012005-04-17 16:05:31 -0500768
769 return;
770}
771
772/************************************************************************/
773/* */
774/* lpfc_parse_vpd */
775/* This routine will parse the VPD data */
776/* */
777/************************************************************************/
778static int
James Smart2e0fef82007-06-17 19:56:36 -0500779lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500780{
781 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500782 int Length;
dea31012005-04-17 16:05:31 -0500783 int i, j;
784 int finished = 0;
785 int index = 0;
786
787 if (!vpd)
788 return 0;
789
790 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500791 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400792 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500793 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
794 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500795 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500796 switch (vpd[index]) {
797 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500798 case 0x91:
dea31012005-04-17 16:05:31 -0500799 index += 1;
800 lenlo = vpd[index];
801 index += 1;
802 lenhi = vpd[index];
803 index += 1;
804 i = ((((unsigned short)lenhi) << 8) + lenlo);
805 index += i;
806 break;
807 case 0x90:
808 index += 1;
809 lenlo = vpd[index];
810 index += 1;
811 lenhi = vpd[index];
812 index += 1;
813 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500814 if (Length > len - index)
815 Length = len - index;
dea31012005-04-17 16:05:31 -0500816 while (Length > 0) {
817 /* Look for Serial Number */
818 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
819 index += 2;
820 i = vpd[index];
821 index += 1;
822 j = 0;
823 Length -= (3+i);
824 while(i--) {
825 phba->SerialNumber[j++] = vpd[index++];
826 if (j == 31)
827 break;
828 }
829 phba->SerialNumber[j] = 0;
830 continue;
831 }
832 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
833 phba->vpd_flag |= VPD_MODEL_DESC;
834 index += 2;
835 i = vpd[index];
836 index += 1;
837 j = 0;
838 Length -= (3+i);
839 while(i--) {
840 phba->ModelDesc[j++] = vpd[index++];
841 if (j == 255)
842 break;
843 }
844 phba->ModelDesc[j] = 0;
845 continue;
846 }
847 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
848 phba->vpd_flag |= VPD_MODEL_NAME;
849 index += 2;
850 i = vpd[index];
851 index += 1;
852 j = 0;
853 Length -= (3+i);
854 while(i--) {
855 phba->ModelName[j++] = vpd[index++];
856 if (j == 79)
857 break;
858 }
859 phba->ModelName[j] = 0;
860 continue;
861 }
862 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
863 phba->vpd_flag |= VPD_PROGRAM_TYPE;
864 index += 2;
865 i = vpd[index];
866 index += 1;
867 j = 0;
868 Length -= (3+i);
869 while(i--) {
870 phba->ProgramType[j++] = vpd[index++];
871 if (j == 255)
872 break;
873 }
874 phba->ProgramType[j] = 0;
875 continue;
876 }
877 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
878 phba->vpd_flag |= VPD_PORT;
879 index += 2;
880 i = vpd[index];
881 index += 1;
882 j = 0;
883 Length -= (3+i);
884 while(i--) {
885 phba->Port[j++] = vpd[index++];
886 if (j == 19)
887 break;
888 }
889 phba->Port[j] = 0;
890 continue;
891 }
892 else {
893 index += 2;
894 i = vpd[index];
895 index += 1;
896 index += i;
897 Length -= (3 + i);
898 }
899 }
900 finished = 0;
901 break;
902 case 0x78:
903 finished = 1;
904 break;
905 default:
906 index ++;
907 break;
908 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500909 }
dea31012005-04-17 16:05:31 -0500910
911 return(1);
912}
913
914static void
James Smart2e0fef82007-06-17 19:56:36 -0500915lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -0500916{
917 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -0500918 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500919 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500920 struct {
921 char * name;
922 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500923 char * bus;
James Smart18a3b592006-12-02 13:35:08 -0500924 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500925
926 if (mdp && mdp[0] != '\0'
927 && descp && descp[0] != '\0')
928 return;
929
930 if (phba->lmt & LMT_10Gb)
931 max_speed = 10;
932 else if (phba->lmt & LMT_8Gb)
933 max_speed = 8;
934 else if (phba->lmt & LMT_4Gb)
935 max_speed = 4;
936 else if (phba->lmt & LMT_2Gb)
937 max_speed = 2;
938 else
939 max_speed = 1;
dea31012005-04-17 16:05:31 -0500940
941 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -0500942
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500943 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400944 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -0500945 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400946 break;
dea31012005-04-17 16:05:31 -0500947 case PCI_DEVICE_ID_SUPERFLY:
948 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -0500949 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500950 else
James Smart18a3b592006-12-02 13:35:08 -0500951 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500952 break;
953 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -0500954 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500955 break;
956 case PCI_DEVICE_ID_CENTAUR:
957 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -0500958 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500959 else
James Smart18a3b592006-12-02 13:35:08 -0500960 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500961 break;
962 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -0500963 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500964 break;
965 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -0500966 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500967 break;
968 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -0500969 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500970 break;
971 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -0500972 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500973 break;
974 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -0500975 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500976 break;
977 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -0500978 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500979 break;
980 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -0500981 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -0500982 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500983 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500984 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500985 break;
986 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -0500987 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500988 break;
989 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -0500990 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500991 break;
992 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500993 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500994 break;
995 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -0500996 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500997 break;
dea31012005-04-17 16:05:31 -0500998 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -0500999 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001000 break;
1001 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001002 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001003 break;
1004 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001005 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001006 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001007 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001008 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001009 break;
1010 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001011 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001012 break;
dea31012005-04-17 16:05:31 -05001013 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001014 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001015 break;
1016 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001017 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001018 break;
1019 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001020 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001021 break;
1022 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001023 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001024 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001025 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001026 m = (typeof(m)){"LP11000-S", max_speed,
1027 "PCI-X2"};
1028 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001029 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001030 m = (typeof(m)){"LPe11000-S", max_speed,
1031 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001032 break;
James Smartb87eab32007-04-25 09:53:28 -04001033 case PCI_DEVICE_ID_SAT:
1034 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1035 break;
1036 case PCI_DEVICE_ID_SAT_MID:
1037 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1038 break;
1039 case PCI_DEVICE_ID_SAT_SMB:
1040 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1041 break;
1042 case PCI_DEVICE_ID_SAT_DCSP:
1043 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1044 break;
1045 case PCI_DEVICE_ID_SAT_SCSP:
1046 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1047 break;
1048 case PCI_DEVICE_ID_SAT_S:
1049 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1050 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001051 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001052 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001053 break;
dea31012005-04-17 16:05:31 -05001054 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001055
1056 if (mdp && mdp[0] == '\0')
1057 snprintf(mdp, 79,"%s", m.name);
1058 if (descp && descp[0] == '\0')
1059 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001060 "Emulex %s %dGb %s Fibre Channel Adapter",
1061 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001062}
1063
1064/**************************************************/
1065/* lpfc_post_buffer */
1066/* */
1067/* This routine will post count buffers to the */
1068/* ring with the QUE_RING_BUF_CN command. This */
1069/* allows 3 buffers / command to be posted. */
1070/* Returns the number of buffers NOT posted. */
1071/**************************************************/
1072int
James Smart2e0fef82007-06-17 19:56:36 -05001073lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -05001074 int type)
1075{
1076 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001077 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001078 struct lpfc_dmabuf *mp1, *mp2;
1079
1080 cnt += pring->missbufcnt;
1081
1082 /* While there are buffers to post */
1083 while (cnt > 0) {
1084 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001085 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001086 if (iocb == NULL) {
1087 pring->missbufcnt = cnt;
1088 return cnt;
1089 }
dea31012005-04-17 16:05:31 -05001090 icmd = &iocb->iocb;
1091
1092 /* 2 buffers can be posted per command */
1093 /* Allocate buffer to post */
1094 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1095 if (mp1)
1096 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1097 &mp1->phys);
1098 if (mp1 == 0 || mp1->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001099 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001100 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001101 pring->missbufcnt = cnt;
1102 return cnt;
1103 }
1104
1105 INIT_LIST_HEAD(&mp1->list);
1106 /* Allocate buffer to post */
1107 if (cnt > 1) {
1108 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1109 if (mp2)
1110 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1111 &mp2->phys);
1112 if (mp2 == 0 || mp2->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001113 kfree(mp2);
dea31012005-04-17 16:05:31 -05001114 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1115 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001116 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001117 pring->missbufcnt = cnt;
1118 return cnt;
1119 }
1120
1121 INIT_LIST_HEAD(&mp2->list);
1122 } else {
1123 mp2 = NULL;
1124 }
1125
1126 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1127 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1128 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1129 icmd->ulpBdeCount = 1;
1130 cnt--;
1131 if (mp2) {
1132 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1133 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1134 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1135 cnt--;
1136 icmd->ulpBdeCount = 2;
1137 }
1138
1139 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1140 icmd->ulpLe = 1;
1141
dea31012005-04-17 16:05:31 -05001142 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1143 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1144 kfree(mp1);
1145 cnt++;
1146 if (mp2) {
1147 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1148 kfree(mp2);
1149 cnt++;
1150 }
James Bottomley604a3e32005-10-29 10:28:33 -05001151 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001152 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001153 return cnt;
1154 }
dea31012005-04-17 16:05:31 -05001155 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001156 if (mp2)
dea31012005-04-17 16:05:31 -05001157 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001158 }
1159 pring->missbufcnt = 0;
1160 return 0;
1161}
1162
1163/************************************************************************/
1164/* */
1165/* lpfc_post_rcv_buf */
1166/* This routine post initial rcv buffers to the configured rings */
1167/* */
1168/************************************************************************/
1169static int
James Smart2e0fef82007-06-17 19:56:36 -05001170lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001171{
1172 struct lpfc_sli *psli = &phba->sli;
1173
1174 /* Ring 0, ELS / CT buffers */
1175 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1176 /* Ring 2 - FCP no buffers needed */
1177
1178 return 0;
1179}
1180
1181#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1182
1183/************************************************************************/
1184/* */
1185/* lpfc_sha_init */
1186/* */
1187/************************************************************************/
1188static void
1189lpfc_sha_init(uint32_t * HashResultPointer)
1190{
1191 HashResultPointer[0] = 0x67452301;
1192 HashResultPointer[1] = 0xEFCDAB89;
1193 HashResultPointer[2] = 0x98BADCFE;
1194 HashResultPointer[3] = 0x10325476;
1195 HashResultPointer[4] = 0xC3D2E1F0;
1196}
1197
1198/************************************************************************/
1199/* */
1200/* lpfc_sha_iterate */
1201/* */
1202/************************************************************************/
1203static void
1204lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1205{
1206 int t;
1207 uint32_t TEMP;
1208 uint32_t A, B, C, D, E;
1209 t = 16;
1210 do {
1211 HashWorkingPointer[t] =
1212 S(1,
1213 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1214 8] ^
1215 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1216 } while (++t <= 79);
1217 t = 0;
1218 A = HashResultPointer[0];
1219 B = HashResultPointer[1];
1220 C = HashResultPointer[2];
1221 D = HashResultPointer[3];
1222 E = HashResultPointer[4];
1223
1224 do {
1225 if (t < 20) {
1226 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1227 } else if (t < 40) {
1228 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1229 } else if (t < 60) {
1230 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1231 } else {
1232 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1233 }
1234 TEMP += S(5, A) + E + HashWorkingPointer[t];
1235 E = D;
1236 D = C;
1237 C = S(30, B);
1238 B = A;
1239 A = TEMP;
1240 } while (++t <= 79);
1241
1242 HashResultPointer[0] += A;
1243 HashResultPointer[1] += B;
1244 HashResultPointer[2] += C;
1245 HashResultPointer[3] += D;
1246 HashResultPointer[4] += E;
1247
1248}
1249
1250/************************************************************************/
1251/* */
1252/* lpfc_challenge_key */
1253/* */
1254/************************************************************************/
1255static void
1256lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1257{
1258 *HashWorking = (*RandomChallenge ^ *HashWorking);
1259}
1260
1261/************************************************************************/
1262/* */
1263/* lpfc_hba_init */
1264/* */
1265/************************************************************************/
1266void
1267lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1268{
1269 int t;
1270 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001271 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001272
1273 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1274 if (!HashWorking)
1275 return;
1276
1277 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1278 HashWorking[0] = HashWorking[78] = *pwwnn++;
1279 HashWorking[1] = HashWorking[79] = *pwwnn;
1280
1281 for (t = 0; t < 7; t++)
1282 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1283
1284 lpfc_sha_init(hbainit);
1285 lpfc_sha_iterate(hbainit, HashWorking);
1286 kfree(HashWorking);
1287}
1288
1289static void
James Smart2e0fef82007-06-17 19:56:36 -05001290lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001291{
1292 struct lpfc_nodelist *ndlp, *next_ndlp;
1293
1294 /* clean up phba - lpfc specific */
James Smart2e0fef82007-06-17 19:56:36 -05001295 lpfc_can_disctmo(vport);
1296 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart329f9bc2007-04-25 09:53:01 -04001297 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001298 return;
1299}
1300
1301static void
1302lpfc_establish_link_tmo(unsigned long ptr)
1303{
James Smart92d7f7b2007-06-17 19:56:38 -05001304 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James Smart549e55c2007-08-02 11:09:51 -04001305 struct lpfc_vport **vports;
dea31012005-04-17 16:05:31 -05001306 unsigned long iflag;
James Smart549e55c2007-08-02 11:09:51 -04001307 int i;
dea31012005-04-17 16:05:31 -05001308
dea31012005-04-17 16:05:31 -05001309 /* Re-establishing Link, timer expired */
1310 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001311 "1300 Re-establishing Link, timer expired "
dea31012005-04-17 16:05:31 -05001312 "Data: x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001313 phba->pport->fc_flag, phba->pport->port_state);
James Smart549e55c2007-08-02 11:09:51 -04001314 vports = lpfc_create_vport_work_array(phba);
1315 if (vports != NULL)
1316 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1317 struct Scsi_Host *shost;
1318 shost = lpfc_shost_from_vport(vports[i]);
1319 spin_lock_irqsave(shost->host_lock, iflag);
1320 vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1321 spin_unlock_irqrestore(shost->host_lock, iflag);
1322 }
1323 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001324}
1325
James Smart92d7f7b2007-06-17 19:56:38 -05001326void
1327lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001328{
James Smart92d7f7b2007-06-17 19:56:38 -05001329 del_timer_sync(&vport->els_tmofunc);
1330 del_timer_sync(&vport->fc_fdmitmo);
1331 lpfc_can_disctmo(vport);
1332 return;
dea31012005-04-17 16:05:31 -05001333}
1334
James Smart2e0fef82007-06-17 19:56:36 -05001335static void
James Smart92d7f7b2007-06-17 19:56:38 -05001336lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001337{
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001338 del_timer_sync(&phba->fcp_poll_timer);
dea31012005-04-17 16:05:31 -05001339 del_timer_sync(&phba->fc_estabtmo);
James Smart51ef4c22007-08-02 11:10:31 -04001340 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001341 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001342 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001343 phba->hb_outstanding = 0;
1344 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001345 return;
dea31012005-04-17 16:05:31 -05001346}
1347
1348int
James Smart2e0fef82007-06-17 19:56:36 -05001349lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001350{
James Smart2e0fef82007-06-17 19:56:36 -05001351 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001352 struct lpfc_vport **vports;
1353 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001354
dea31012005-04-17 16:05:31 -05001355 if (!phba)
1356 return 0;
1357
James Smart2e0fef82007-06-17 19:56:36 -05001358 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001359 return 0;
1360
James Smarted957682007-06-17 19:56:37 -05001361 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001362 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001363
James Smart46fa3112007-04-25 09:51:45 -04001364 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001365
James Smart46fa3112007-04-25 09:51:45 -04001366 if (!lpfc_sli_queue_setup(phba)) {
1367 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001368 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001369 }
1370
1371 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1372 lpfc_unblock_mgmt_io(phba);
1373 return 1;
1374 }
dea31012005-04-17 16:05:31 -05001375
James Smart549e55c2007-08-02 11:09:51 -04001376 vports = lpfc_create_vport_work_array(phba);
1377 if (vports != NULL)
1378 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1379 struct Scsi_Host *shost;
1380 shost = lpfc_shost_from_vport(vports[i]);
1381 spin_lock_irq(shost->host_lock);
1382 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1383 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1384 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1385 spin_unlock_irq(shost->host_lock);
1386 }
1387 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001388
James Smart46fa3112007-04-25 09:51:45 -04001389 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001390 return 0;
1391}
1392
James Smart46fa3112007-04-25 09:51:45 -04001393void
1394lpfc_block_mgmt_io(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -05001395{
dea31012005-04-17 16:05:31 -05001396 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001397
James Smart2e0fef82007-06-17 19:56:36 -05001398 spin_lock_irqsave(&phba->hbalock, iflag);
1399 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1400 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001401}
1402
1403void
1404lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1405{
1406 unsigned long iflag;
1407
James Smart2e0fef82007-06-17 19:56:36 -05001408 spin_lock_irqsave(&phba->hbalock, iflag);
1409 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1410 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001411}
1412
1413void
1414lpfc_offline_prep(struct lpfc_hba * phba)
1415{
James Smart2e0fef82007-06-17 19:56:36 -05001416 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001417 struct lpfc_nodelist *ndlp, *next_ndlp;
dea31012005-04-17 16:05:31 -05001418
James Smart2e0fef82007-06-17 19:56:36 -05001419 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001420 return;
dea31012005-04-17 16:05:31 -05001421
James Smart46fa3112007-04-25 09:51:45 -04001422 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001423
1424 lpfc_linkdown(phba);
1425
James Smart46fa3112007-04-25 09:51:45 -04001426 /* Issue an unreg_login to all nodes */
James Smart2e0fef82007-06-17 19:56:36 -05001427 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart685f0bf2007-04-25 09:53:08 -04001428 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001429 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001430
James Smart46fa3112007-04-25 09:51:45 -04001431 lpfc_sli_flush_mbox_queue(phba);
1432}
1433
1434void
James Smart2e0fef82007-06-17 19:56:36 -05001435lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001436{
James Smart549e55c2007-08-02 11:09:51 -04001437 struct Scsi_Host *shost;
1438 struct lpfc_vport **vports;
1439 int i;
James Smart46fa3112007-04-25 09:51:45 -04001440
James Smart549e55c2007-08-02 11:09:51 -04001441 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001442 return;
James Smart688a8862006-07-06 15:49:56 -04001443
dea31012005-04-17 16:05:31 -05001444 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001445 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04001446 vports = lpfc_create_vport_work_array(phba);
1447 if (vports != NULL)
1448 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
1449 lpfc_stop_vport_timers(vports[i]);
1450 lpfc_destroy_vport_work_array(vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001451 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001452 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05001453 /* Bring down the SLI Layer and cleanup. The HBA is offline
1454 now. */
1455 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001456 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001457 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001458 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001459 vports = lpfc_create_vport_work_array(phba);
1460 if (vports != NULL)
1461 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1462 shost = lpfc_shost_from_vport(vports[i]);
1463 lpfc_cleanup(vports[i]);
1464 spin_lock_irq(shost->host_lock);
1465 vports[i]->work_port_events = 0;
1466 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1467 spin_unlock_irq(shost->host_lock);
1468 }
1469 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001470}
1471
1472/******************************************************************************
1473* Function name: lpfc_scsi_free
1474*
1475* Description: Called from lpfc_pci_remove_one free internal driver resources
1476*
1477******************************************************************************/
1478static int
James Smart2e0fef82007-06-17 19:56:36 -05001479lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001480{
1481 struct lpfc_scsi_buf *sb, *sb_next;
1482 struct lpfc_iocbq *io, *io_next;
1483
James Smart2e0fef82007-06-17 19:56:36 -05001484 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001485 /* Release all the lpfc_scsi_bufs maintained by this host. */
1486 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1487 list_del(&sb->list);
1488 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001489 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001490 kfree(sb);
1491 phba->total_scsi_bufs--;
1492 }
1493
1494 /* Release all the lpfc_iocbq entries maintained by this host. */
1495 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1496 list_del(&io->list);
1497 kfree(io);
1498 phba->total_iocbq_bufs--;
1499 }
1500
James Smart2e0fef82007-06-17 19:56:36 -05001501 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001502
1503 return 0;
1504}
1505
James Smart2e0fef82007-06-17 19:56:36 -05001506struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04001507lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04001508{
James Smart2e0fef82007-06-17 19:56:36 -05001509 struct lpfc_vport *vport;
1510 struct Scsi_Host *shost;
1511 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001512
James Smart3de2a652007-08-02 11:09:59 -04001513 if (dev != &phba->pcidev->dev)
1514 shost = scsi_host_alloc(&lpfc_vport_template,
1515 sizeof(struct lpfc_vport));
1516 else
1517 shost = scsi_host_alloc(&lpfc_template,
1518 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05001519 if (!shost)
1520 goto out;
James Smart47a86172007-04-25 09:53:22 -04001521
James Smart2e0fef82007-06-17 19:56:36 -05001522 vport = (struct lpfc_vport *) shost->hostdata;
1523 vport->phba = phba;
James Smart47a86172007-04-25 09:53:22 -04001524
James Smart2e0fef82007-06-17 19:56:36 -05001525 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001526 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart47a86172007-04-25 09:53:22 -04001527
James Smart3de2a652007-08-02 11:09:59 -04001528 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001529 shost->unique_id = instance;
1530 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04001531 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05001532 shost->this_id = -1;
1533 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001534 /*
James Smart2e0fef82007-06-17 19:56:36 -05001535 * Set initial can_queue value since 0 is no longer supported and
1536 * scsi_add_host will fail. This will be adjusted later based on the
1537 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001538 */
James Smart2e0fef82007-06-17 19:56:36 -05001539 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04001540 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05001541 shost->transportt = lpfc_vport_transport_template;
1542 vport->port_type = LPFC_NPIV_PORT;
1543 } else {
1544 shost->transportt = lpfc_transport_template;
1545 vport->port_type = LPFC_PHYSICAL_PORT;
1546 }
James Smart47a86172007-04-25 09:53:22 -04001547
James Smart2e0fef82007-06-17 19:56:36 -05001548 /* Initialize all internally managed lists. */
1549 INIT_LIST_HEAD(&vport->fc_nodes);
1550 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001551
James Smart2e0fef82007-06-17 19:56:36 -05001552 init_timer(&vport->fc_disctmo);
1553 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001554 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001555
James Smart2e0fef82007-06-17 19:56:36 -05001556 init_timer(&vport->fc_fdmitmo);
1557 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001558 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001559
James Smart2e0fef82007-06-17 19:56:36 -05001560 init_timer(&vport->els_tmofunc);
1561 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001562 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001563
James Smart3de2a652007-08-02 11:09:59 -04001564 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05001565 if (error)
1566 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001567
James Smart549e55c2007-08-02 11:09:51 -04001568 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001569 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001570 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001571 return vport;
James Smart47a86172007-04-25 09:53:22 -04001572
James Smart2e0fef82007-06-17 19:56:36 -05001573out_put_shost:
1574 scsi_host_put(shost);
1575out:
1576 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001577}
1578
James Smart2e0fef82007-06-17 19:56:36 -05001579void
1580destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001581{
James Smart92d7f7b2007-06-17 19:56:38 -05001582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1583 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001584
James Smart92d7f7b2007-06-17 19:56:38 -05001585 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001586
James Smart858c9f62007-06-17 19:56:39 -05001587 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001588 fc_remove_host(shost);
1589 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001590
James Smart92d7f7b2007-06-17 19:56:38 -05001591 spin_lock_irq(&phba->hbalock);
1592 list_del_init(&vport->listentry);
1593 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001594
James Smart92d7f7b2007-06-17 19:56:38 -05001595 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001596 return;
James Smart47a86172007-04-25 09:53:22 -04001597}
1598
James Smart92d7f7b2007-06-17 19:56:38 -05001599int
1600lpfc_get_instance(void)
1601{
1602 int instance = 0;
1603
1604 /* Assign an unused number */
1605 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1606 return -1;
1607 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1608 return -1;
1609 return instance;
1610}
1611
James Smart858c9f62007-06-17 19:56:39 -05001612/*
1613 * Note: there is no scan_start function as adapter initialization
1614 * will have asynchronously kicked off the link initialization.
1615 */
James Smart47a86172007-04-25 09:53:22 -04001616
1617int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1618{
James Smart2e0fef82007-06-17 19:56:36 -05001619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1620 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001621 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001622
James Smart858c9f62007-06-17 19:56:39 -05001623 spin_lock_irq(shost->host_lock);
1624
James Smart51ef4c22007-08-02 11:10:31 -04001625 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05001626 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001627 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001628 }
James Smart2e0fef82007-06-17 19:56:36 -05001629 if (time >= 30 * HZ) {
1630 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001631 "0461 Scanning longer than 30 "
1632 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001633 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001634 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001635 }
1636 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1637 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001638 "0465 Link down longer than 15 "
1639 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05001640 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001641 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001642 }
1643
James Smart2e0fef82007-06-17 19:56:36 -05001644 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001645 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001646 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001647 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001648 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001649 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001650 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001651 goto finished;
1652
1653 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001654
1655finished:
James Smart858c9f62007-06-17 19:56:39 -05001656 spin_unlock_irq(shost->host_lock);
1657 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001658}
1659
1660void lpfc_host_attrib_init(struct Scsi_Host *shost)
1661{
1662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1663 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001664 /*
James Smart2e0fef82007-06-17 19:56:36 -05001665 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001666 */
1667
James Smart2e0fef82007-06-17 19:56:36 -05001668 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1669 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001670 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1671
1672 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001673 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001674 fc_host_supported_fc4s(shost)[2] = 1;
1675 fc_host_supported_fc4s(shost)[7] = 1;
1676
James Smart92d7f7b2007-06-17 19:56:38 -05001677 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1678 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001679
1680 fc_host_supported_speeds(shost) = 0;
1681 if (phba->lmt & LMT_10Gb)
1682 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1683 if (phba->lmt & LMT_4Gb)
1684 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1685 if (phba->lmt & LMT_2Gb)
1686 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1687 if (phba->lmt & LMT_1Gb)
1688 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1689
1690 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001691 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1692 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001693
1694 /* This value is also unchanging */
1695 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001696 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001697 fc_host_active_fc4s(shost)[2] = 1;
1698 fc_host_active_fc4s(shost)[7] = 1;
1699
James Smart92d7f7b2007-06-17 19:56:38 -05001700 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001701 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001702 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001703 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001704}
dea31012005-04-17 16:05:31 -05001705
1706static int __devinit
1707lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1708{
James Smart2e0fef82007-06-17 19:56:36 -05001709 struct lpfc_vport *vport = NULL;
1710 struct lpfc_hba *phba;
1711 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001712 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001713 struct Scsi_Host *shost = NULL;
James Smart51ef4c22007-08-02 11:10:31 -04001714 void *ptr;
dea31012005-04-17 16:05:31 -05001715 unsigned long bar0map_len, bar2map_len;
James Bottomleya5785032007-07-14 18:47:04 -05001716 int error = -ENODEV;
James Smart51ef4c22007-08-02 11:10:31 -04001717 int i, hbq_count;
James Bottomley604a3e32005-10-29 10:28:33 -05001718 uint16_t iotag;
dea31012005-04-17 16:05:31 -05001719
1720 if (pci_enable_device(pdev))
1721 goto out;
1722 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1723 goto out_disable_device;
1724
James Smart2e0fef82007-06-17 19:56:36 -05001725 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1726 if (!phba)
dea31012005-04-17 16:05:31 -05001727 goto out_release_regions;
1728
James Smart2e0fef82007-06-17 19:56:36 -05001729 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001730
dea31012005-04-17 16:05:31 -05001731 phba->pcidev = pdev;
1732
1733 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001734 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001735 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001736
James Smart2e0fef82007-06-17 19:56:36 -05001737 INIT_LIST_HEAD(&phba->port_list);
James Smart2e0fef82007-06-17 19:56:36 -05001738 /*
1739 * Get all the module params for configuring this host and then
1740 * establish the host.
1741 */
1742 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001743 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05001744
1745 /* Initialize timers used by driver */
1746 init_timer(&phba->fc_estabtmo);
1747 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1748 phba->fc_estabtmo.data = (unsigned long)phba;
dea31012005-04-17 16:05:31 -05001749
James Smart858c9f62007-06-17 19:56:39 -05001750 init_timer(&phba->hb_tmofunc);
1751 phba->hb_tmofunc.function = lpfc_hb_timeout;
1752 phba->hb_tmofunc.data = (unsigned long)phba;
1753
dea31012005-04-17 16:05:31 -05001754 psli = &phba->sli;
1755 init_timer(&psli->mbox_tmo);
1756 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001757 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001758 init_timer(&phba->fcp_poll_timer);
1759 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001760 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001761 init_timer(&phba->fabric_block_timer);
1762 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1763 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001764
dea31012005-04-17 16:05:31 -05001765 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07001766 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05001767
1768 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1769 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1770 goto out_idr_remove;
1771
1772 /*
1773 * Get the bus address of Bar0 and Bar2 and the number of bytes
1774 * required by each mapping.
1775 */
1776 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1777 bar0map_len = pci_resource_len(phba->pcidev, 0);
1778
1779 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1780 bar2map_len = pci_resource_len(phba->pcidev, 2);
1781
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001782 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001783 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001784 if (!phba->slim_memmap_p) {
1785 error = -ENODEV;
1786 dev_printk(KERN_ERR, &pdev->dev,
1787 "ioremap failed for SLIM memory.\n");
1788 goto out_idr_remove;
1789 }
1790
1791 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001792 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001793 if (!phba->ctrl_regs_memmap_p) {
1794 error = -ENODEV;
1795 dev_printk(KERN_ERR, &pdev->dev,
1796 "ioremap failed for HBA control registers.\n");
1797 goto out_iounmap_slim;
1798 }
dea31012005-04-17 16:05:31 -05001799
1800 /* Allocate memory for SLI-2 structures */
1801 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1802 &phba->slim2p_mapping, GFP_KERNEL);
1803 if (!phba->slim2p)
1804 goto out_iounmap;
1805
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001806 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05001807
James Smarted957682007-06-17 19:56:37 -05001808 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1809 lpfc_sli_hbq_size(),
1810 &phba->hbqslimp.phys,
1811 GFP_KERNEL);
1812 if (!phba->hbqslimp.virt)
1813 goto out_free_slim;
1814
James Smart51ef4c22007-08-02 11:10:31 -04001815 hbq_count = lpfc_sli_hbq_count();
1816 ptr = phba->hbqslimp.virt;
1817 for (i = 0; i < hbq_count; ++i) {
1818 phba->hbqs[i].hbq_virt = ptr;
1819 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
1820 ptr += (lpfc_hbq_defs[i]->entry_count *
1821 sizeof(struct lpfc_hbq_entry));
1822 }
1823 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
1824 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
1825
James Smarted957682007-06-17 19:56:37 -05001826 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
1827
dea31012005-04-17 16:05:31 -05001828 /* Initialize the SLI Layer to run with lpfc HBAs. */
1829 lpfc_sli_setup(phba);
1830 lpfc_sli_queue_setup(phba);
1831
1832 error = lpfc_mem_alloc(phba);
1833 if (error)
James Smarted957682007-06-17 19:56:37 -05001834 goto out_free_hbqslimp;
dea31012005-04-17 16:05:31 -05001835
1836 /* Initialize and populate the iocb list per host. */
1837 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1838 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001839 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001840 if (iocbq_entry == NULL) {
1841 printk(KERN_ERR "%s: only allocated %d iocbs of "
1842 "expected %d count. Unloading driver.\n",
1843 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1844 error = -ENOMEM;
1845 goto out_free_iocbq;
1846 }
1847
James Bottomley604a3e32005-10-29 10:28:33 -05001848 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1849 if (iotag == 0) {
1850 kfree (iocbq_entry);
1851 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1852 "Unloading driver.\n",
1853 __FUNCTION__);
1854 error = -ENOMEM;
1855 goto out_free_iocbq;
1856 }
James Smart2e0fef82007-06-17 19:56:36 -05001857
1858 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001859 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1860 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05001861 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001862 }
1863
1864 /* Initialize HBA structure */
1865 phba->fc_edtov = FF_DEF_EDTOV;
1866 phba->fc_ratov = FF_DEF_RATOV;
1867 phba->fc_altov = FF_DEF_ALTOV;
1868 phba->fc_arbtov = FF_DEF_ARBTOV;
1869
1870 INIT_LIST_HEAD(&phba->work_list);
1871 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1872 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1873
1874 /* Startup the kernel thread for this host adapter. */
1875 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1876 "lpfc_worker_%d", phba->brd_no);
1877 if (IS_ERR(phba->worker_thread)) {
1878 error = PTR_ERR(phba->worker_thread);
1879 goto out_free_iocbq;
1880 }
1881
dea31012005-04-17 16:05:31 -05001882 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001883 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05001884 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1885
James Smart92d7f7b2007-06-17 19:56:38 -05001886 /* Initialize list of fabric iocbs */
1887 INIT_LIST_HEAD(&phba->fabric_iocb_list);
1888
James Smart3de2a652007-08-02 11:09:59 -04001889 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05001890 if (!vport)
1891 goto out_kthread_stop;
1892
1893 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001894 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05001895 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001896
James Smart92d7f7b2007-06-17 19:56:38 -05001897 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05001898
James Smart4ff43242006-12-02 13:34:56 -05001899 if (phba->cfg_use_msi) {
1900 error = pci_enable_msi(phba->pcidev);
James Smart51ef4c22007-08-02 11:10:31 -04001901 if (!error)
1902 phba->using_msi = 1;
1903 else
James Smarte8b62012007-08-02 11:10:09 -04001904 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1905 "0452 Enable MSI failed, continuing "
1906 "with IRQ\n");
James Smart4ff43242006-12-02 13:34:56 -05001907 }
1908
Thomas Gleixner1d6f3592006-07-01 19:29:42 -07001909 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
James Smart2e0fef82007-06-17 19:56:36 -05001910 LPFC_DRIVER_NAME, phba);
dea31012005-04-17 16:05:31 -05001911 if (error) {
1912 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001913 "0451 Enable interrupt handler failed\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001914 goto out_disable_msi;
dea31012005-04-17 16:05:31 -05001915 }
dea31012005-04-17 16:05:31 -05001916
James Smart2e0fef82007-06-17 19:56:36 -05001917 phba->MBslimaddr = phba->slim_memmap_p;
1918 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1919 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1920 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1921 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1922
James Smart92d7f7b2007-06-17 19:56:38 -05001923 if (lpfc_alloc_sysfs_attr(vport))
dea31012005-04-17 16:05:31 -05001924 goto out_free_irq;
1925
James Smart858c9f62007-06-17 19:56:39 -05001926 if (lpfc_sli_hba_setup(phba))
1927 goto out_remove_device;
1928
1929 /*
1930 * hba setup may have changed the hba_queue_depth so we need to adjust
1931 * the value of can_queue.
1932 */
1933 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1934
1935 lpfc_host_attrib_init(shost);
1936
James Smart2e0fef82007-06-17 19:56:36 -05001937 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1938 spin_lock_irq(shost->host_lock);
1939 lpfc_poll_start_timer(phba);
1940 spin_unlock_irq(shost->host_lock);
1941 }
James Smart8f6d98d2006-08-01 07:34:00 -04001942
James Smart858c9f62007-06-17 19:56:39 -05001943 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05001944
dea31012005-04-17 16:05:31 -05001945 return 0;
1946
James Smart858c9f62007-06-17 19:56:39 -05001947out_remove_device:
1948 lpfc_free_sysfs_attr(vport);
1949 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04001950 vport->load_flag |= FC_UNLOADING;
James Smart858c9f62007-06-17 19:56:39 -05001951 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001952out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05001953 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001954 phba->pport->work_port_events = 0;
dea31012005-04-17 16:05:31 -05001955 free_irq(phba->pcidev->irq, phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001956out_disable_msi:
James Smart51ef4c22007-08-02 11:10:31 -04001957 if (phba->using_msi)
1958 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05001959 destroy_port(vport);
dea31012005-04-17 16:05:31 -05001960out_kthread_stop:
1961 kthread_stop(phba->worker_thread);
1962out_free_iocbq:
1963 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1964 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05001965 kfree(iocbq_entry);
1966 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05001967 }
1968 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05001969out_free_hbqslimp:
1970 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
1971 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05001972out_free_slim:
1973 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1974 phba->slim2p_mapping);
1975out_iounmap:
1976 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001977out_iounmap_slim:
dea31012005-04-17 16:05:31 -05001978 iounmap(phba->slim_memmap_p);
1979out_idr_remove:
1980 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05001981out_free_phba:
1982 kfree(phba);
dea31012005-04-17 16:05:31 -05001983out_release_regions:
1984 pci_release_regions(pdev);
1985out_disable_device:
1986 pci_disable_device(pdev);
1987out:
James Smartdefbcf12006-04-16 22:26:50 -04001988 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05001989 if (shost)
1990 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05001991 return error;
1992}
1993
1994static void __devexit
1995lpfc_pci_remove_one(struct pci_dev *pdev)
1996{
James Smart2e0fef82007-06-17 19:56:36 -05001997 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1998 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1999 struct lpfc_hba *phba = vport->phba;
James Smart549e55c2007-08-02 11:09:51 -04002000 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04002001 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002002 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002003
James Smart858c9f62007-06-17 19:56:39 -05002004 kfree(vport->vname);
2005 lpfc_free_sysfs_attr(vport);
2006
2007 fc_remove_host(shost);
2008 scsi_remove_host(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002009 /*
2010 * Bring down the SLI Layer. This step disable all interrupts,
2011 * clears the rings, discards all mailbox commands, and resets
2012 * the HBA.
2013 */
2014 lpfc_sli_hba_down(phba);
2015 lpfc_sli_brdrestart(phba);
2016
James Smart92d7f7b2007-06-17 19:56:38 -05002017 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002018 spin_lock_irq(&phba->hbalock);
2019 list_del_init(&vport->listentry);
2020 spin_unlock_irq(&phba->hbalock);
2021
James Smart858c9f62007-06-17 19:56:39 -05002022 lpfc_debugfs_terminate(vport);
2023 lpfc_cleanup(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002024
2025 kthread_stop(phba->worker_thread);
2026
2027 /* Release the irq reservation */
2028 free_irq(phba->pcidev->irq, phba);
James Smart51ef4c22007-08-02 11:10:31 -04002029 if (phba->using_msi)
2030 pci_disable_msi(phba->pcidev);
dea31012005-04-17 16:05:31 -05002031
2032 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002033 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002034
2035 /*
2036 * Call scsi_free before mem_free since scsi bufs are released to their
2037 * corresponding pools here.
2038 */
2039 lpfc_scsi_free(phba);
2040 lpfc_mem_free(phba);
2041
James Smarted957682007-06-17 19:56:37 -05002042 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2043 phba->hbqslimp.phys);
2044
James Smart2e0fef82007-06-17 19:56:36 -05002045 /* Free resources associated with SLI2 interface */
2046 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2047 phba->slim2p, phba->slim2p_mapping);
2048
2049 /* unmap adapter SLIM and Control Registers */
2050 iounmap(phba->ctrl_regs_memmap_p);
2051 iounmap(phba->slim_memmap_p);
2052
2053 idr_remove(&lpfc_hba_index, phba->brd_no);
2054
2055 kfree(phba);
2056
2057 pci_release_regions(pdev);
2058 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002059}
2060
Linas Vepstas8d63f372007-02-14 14:28:36 -06002061/**
2062 * lpfc_io_error_detected - called when PCI error is detected
2063 * @pdev: Pointer to PCI device
2064 * @state: The current pci conneection state
2065 *
2066 * This function is called after a PCI bus error affecting
2067 * this device has been detected.
2068 */
2069static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2070 pci_channel_state_t state)
2071{
James Smart51ef4c22007-08-02 11:10:31 -04002072 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2073 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002074 struct lpfc_sli *psli = &phba->sli;
2075 struct lpfc_sli_ring *pring;
2076
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002077 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002078 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002079
Linas Vepstas8d63f372007-02-14 14:28:36 -06002080 pci_disable_device(pdev);
2081 /*
2082 * There may be I/Os dropped by the firmware.
2083 * Error iocb (I/O) on txcmplq and let the SCSI layer
2084 * retry it after re-establishing link.
2085 */
2086 pring = &psli->ring[psli->fcp_ring];
2087 lpfc_sli_abort_iocb_ring(phba, pring);
2088
James Smart51ef4c22007-08-02 11:10:31 -04002089 /* Release the irq reservation */
2090 free_irq(phba->pcidev->irq, phba);
2091 if (phba->using_msi)
2092 pci_disable_msi(phba->pcidev);
2093
Linas Vepstas8d63f372007-02-14 14:28:36 -06002094 /* Request a slot reset. */
2095 return PCI_ERS_RESULT_NEED_RESET;
2096}
2097
2098/**
2099 * lpfc_io_slot_reset - called after the pci bus has been reset.
2100 * @pdev: Pointer to PCI device
2101 *
2102 * Restart the card from scratch, as if from a cold-boot.
2103 */
2104static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2105{
James Smart51ef4c22007-08-02 11:10:31 -04002106 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2107 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002108 struct lpfc_sli *psli = &phba->sli;
2109 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2110
2111 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2112 if (pci_enable_device_bars(pdev, bars)) {
2113 printk(KERN_ERR "lpfc: Cannot re-enable "
2114 "PCI device after reset.\n");
2115 return PCI_ERS_RESULT_DISCONNECT;
2116 }
2117
2118 pci_set_master(pdev);
2119
2120 /* Re-establishing Link */
James Smart51ef4c22007-08-02 11:10:31 -04002121 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002122 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart51ef4c22007-08-02 11:10:31 -04002123 spin_unlock_irq(shost->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002124
James Smart92d7f7b2007-06-17 19:56:38 -05002125 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002126 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002127 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002128
2129
2130 /* Take device offline; this will perform cleanup */
2131 lpfc_offline(phba);
2132 lpfc_sli_brdrestart(phba);
2133
2134 return PCI_ERS_RESULT_RECOVERED;
2135}
2136
2137/**
2138 * lpfc_io_resume - called when traffic can start flowing again.
2139 * @pdev: Pointer to PCI device
2140 *
2141 * This callback is called when the error recovery driver tells us that
2142 * its OK to resume normal operation.
2143 */
2144static void lpfc_io_resume(struct pci_dev *pdev)
2145{
James Smart51ef4c22007-08-02 11:10:31 -04002146 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2147 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06002148
2149 if (lpfc_online(phba) == 0) {
2150 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2151 }
2152}
2153
dea31012005-04-17 16:05:31 -05002154static struct pci_device_id lpfc_id_table[] = {
2155 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2156 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002157 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2158 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002159 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2160 PCI_ANY_ID, PCI_ANY_ID, },
2161 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2162 PCI_ANY_ID, PCI_ANY_ID, },
2163 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2164 PCI_ANY_ID, PCI_ANY_ID, },
2165 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2166 PCI_ANY_ID, PCI_ANY_ID, },
2167 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2168 PCI_ANY_ID, PCI_ANY_ID, },
2169 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2170 PCI_ANY_ID, PCI_ANY_ID, },
2171 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2172 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002173 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2174 PCI_ANY_ID, PCI_ANY_ID, },
2175 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2176 PCI_ANY_ID, PCI_ANY_ID, },
2177 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2178 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002179 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2180 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002181 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2182 PCI_ANY_ID, PCI_ANY_ID, },
2183 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2184 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002185 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2186 PCI_ANY_ID, PCI_ANY_ID, },
2187 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2188 PCI_ANY_ID, PCI_ANY_ID, },
2189 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2190 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002191 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2192 PCI_ANY_ID, PCI_ANY_ID, },
2193 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2194 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002195 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2196 PCI_ANY_ID, PCI_ANY_ID, },
2197 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2198 PCI_ANY_ID, PCI_ANY_ID, },
2199 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2200 PCI_ANY_ID, PCI_ANY_ID, },
2201 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2202 PCI_ANY_ID, PCI_ANY_ID, },
2203 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2204 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002205 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2206 PCI_ANY_ID, PCI_ANY_ID, },
2207 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2208 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002209 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2210 PCI_ANY_ID, PCI_ANY_ID, },
2211 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2212 PCI_ANY_ID, PCI_ANY_ID, },
2213 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2214 PCI_ANY_ID, PCI_ANY_ID, },
2215 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2216 PCI_ANY_ID, PCI_ANY_ID, },
2217 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2218 PCI_ANY_ID, PCI_ANY_ID, },
2219 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2220 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002221 { 0 }
2222};
2223
2224MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2225
Linas Vepstas8d63f372007-02-14 14:28:36 -06002226static struct pci_error_handlers lpfc_err_handler = {
2227 .error_detected = lpfc_io_error_detected,
2228 .slot_reset = lpfc_io_slot_reset,
2229 .resume = lpfc_io_resume,
2230};
2231
dea31012005-04-17 16:05:31 -05002232static struct pci_driver lpfc_driver = {
2233 .name = LPFC_DRIVER_NAME,
2234 .id_table = lpfc_id_table,
2235 .probe = lpfc_pci_probe_one,
2236 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002237 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002238};
2239
2240static int __init
2241lpfc_init(void)
2242{
2243 int error = 0;
2244
2245 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002246 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002247
2248 lpfc_transport_template =
2249 fc_attach_transport(&lpfc_transport_functions);
James Smart92d7f7b2007-06-17 19:56:38 -05002250 lpfc_vport_transport_template =
2251 fc_attach_transport(&lpfc_vport_transport_functions);
2252 if (!lpfc_transport_template || !lpfc_vport_transport_template)
dea31012005-04-17 16:05:31 -05002253 return -ENOMEM;
2254 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002255 if (error) {
dea31012005-04-17 16:05:31 -05002256 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002257 fc_release_transport(lpfc_vport_transport_template);
2258 }
dea31012005-04-17 16:05:31 -05002259
2260 return error;
2261}
2262
2263static void __exit
2264lpfc_exit(void)
2265{
2266 pci_unregister_driver(&lpfc_driver);
2267 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002268 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002269}
2270
2271module_init(lpfc_init);
2272module_exit(lpfc_exit);
2273MODULE_LICENSE("GPL");
2274MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2275MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2276MODULE_VERSION("0:" LPFC_DRIVER_VERSION);