blob: 484070c829743d76bb0b8d588265cfe3a4cf8bc4 [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
dea31012005-04-17 16:05:31 -050058/************************************************************************/
59/* */
60/* lpfc_config_port_prep */
61/* This routine will do LPFC initialization prior to the */
62/* CONFIG_PORT mailbox command. This will be initialized */
63/* as a SLI layer callback routine. */
64/* This routine returns 0 on success or -ERESTART if it wants */
65/* the SLI layer to reset the HBA and try again. Any */
66/* other return value indicates an error. */
67/* */
68/************************************************************************/
69int
James Smart2e0fef82007-06-17 19:56:36 -050070lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050071{
72 lpfc_vpd_t *vp = &phba->vpd;
73 int i = 0, rc;
74 LPFC_MBOXQ_t *pmb;
75 MAILBOX_t *mb;
76 char *lpfc_vpd_data = NULL;
77 uint16_t offset = 0;
78 static char licensed[56] =
79 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040080 static int init_key = 1;
dea31012005-04-17 16:05:31 -050081
82 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
83 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050084 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050085 return -ENOMEM;
86 }
87
88 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050089 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050090
91 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040092 if (init_key) {
93 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050094
James Smart65a29c12006-07-06 15:50:50 -040095 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
96 *ptext = cpu_to_be32(*ptext);
97 init_key = 0;
98 }
dea31012005-04-17 16:05:31 -050099
100 lpfc_read_nv(phba, pmb);
101 memset((char*)mb->un.varRDnvp.rsvd3, 0,
102 sizeof (mb->un.varRDnvp.rsvd3));
103 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
104 sizeof (licensed));
105
106 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
107
108 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500109 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
dea31012005-04-17 16:05:31 -0500110 "%d:0324 Config Port initialization "
111 "error, mbxCmd x%x READ_NVPARM, "
112 "mbxStatus x%x\n",
113 phba->brd_no,
114 mb->mbxCommand, mb->mbxStatus);
115 mempool_free(pmb, phba->mbox_mem_pool);
116 return -ERESTART;
117 }
118 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500119 sizeof(phba->wwnn));
120 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
121 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500122 }
123
James Smart92d7f7b2007-06-17 19:56:38 -0500124 phba->sli3_options = 0x0;
125
dea31012005-04-17 16:05:31 -0500126 /* Setup and issue mailbox READ REV command */
127 lpfc_read_rev(phba, pmb);
128 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
129 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -0500131 "%d:0439 Adapter failed to init, mbxCmd x%x "
132 "READ_REV, mbxStatus x%x\n",
133 phba->brd_no,
134 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,
147 "%d:0440 Adapter failed to init, READ_REV has "
148 "missing revision information.\n",
149 phba->brd_no);
dea31012005-04-17 16:05:31 -0500150 mempool_free(pmb, phba->mbox_mem_pool);
151 return -ERESTART;
dea31012005-04-17 16:05:31 -0500152 }
153
James Smarted957682007-06-17 19:56:37 -0500154 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
155 return -EINVAL;
156
dea31012005-04-17 16:05:31 -0500157 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500158 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500159 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500160 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
161 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
162 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
163 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500164 vp->rev.biuRev = mb->un.varRdRev.biuRev;
165 vp->rev.smRev = mb->un.varRdRev.smRev;
166 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
167 vp->rev.endecRev = mb->un.varRdRev.endecRev;
168 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
169 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
170 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
171 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
172 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
173 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
174
James Smart92d7f7b2007-06-17 19:56:38 -0500175 /* If the sli feature level is less then 9, we must
176 * tear down all RPIs and VPIs on link down if NPIV
177 * is enabled.
178 */
179 if (vp->rev.feaLevelHigh < 9)
180 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
181
dea31012005-04-17 16:05:31 -0500182 if (lpfc_is_LC_HBA(phba->pcidev->device))
183 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
184 sizeof (phba->RandomData));
185
dea31012005-04-17 16:05:31 -0500186 /* Get adapter VPD information */
187 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
188 if (!pmb->context2)
189 goto out_free_mbox;
190 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
191 if (!lpfc_vpd_data)
192 goto out_free_context2;
193
194 do {
195 lpfc_dump_mem(phba, pmb, offset);
196 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
197
198 if (rc != MBX_SUCCESS) {
199 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
200 "%d:0441 VPD not present on adapter, "
201 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
202 phba->brd_no,
203 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500204 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500205 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500206 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
207 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
dea31012005-04-17 16:05:31 -0500208 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500209 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500210 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500211 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
212 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500213
214 kfree(lpfc_vpd_data);
215out_free_context2:
216 kfree(pmb->context2);
217out_free_mbox:
218 mempool_free(pmb, phba->mbox_mem_pool);
219 return 0;
220}
221
222/************************************************************************/
223/* */
224/* lpfc_config_port_post */
225/* This routine will do LPFC initialization after the */
226/* CONFIG_PORT mailbox command. This will be initialized */
227/* as a SLI layer callback routine. */
228/* This routine returns 0 on success. Any other return value */
229/* indicates an error. */
230/* */
231/************************************************************************/
232int
James Smart2e0fef82007-06-17 19:56:36 -0500233lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500234{
James Smart2e0fef82007-06-17 19:56:36 -0500235 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500236 LPFC_MBOXQ_t *pmb;
237 MAILBOX_t *mb;
238 struct lpfc_dmabuf *mp;
239 struct lpfc_sli *psli = &phba->sli;
240 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500241 int i, j;
242 int rc;
dea31012005-04-17 16:05:31 -0500243
244 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
245 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500246 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500247 return -ENOMEM;
248 }
249 mb = &pmb->mb;
250
dea31012005-04-17 16:05:31 -0500251 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500252 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500253 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500254 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -0500256 "%d:0448 Adapter failed init, mbxCmd x%x "
257 "READ_SPARM mbxStatus x%x\n",
258 phba->brd_no,
259 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500260 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500261 mp = (struct lpfc_dmabuf *) pmb->context1;
262 mempool_free( pmb, phba->mbox_mem_pool);
263 lpfc_mbuf_free(phba, mp->virt, mp->phys);
264 kfree(mp);
265 return -EIO;
266 }
267
268 mp = (struct lpfc_dmabuf *) pmb->context1;
269
James Smart2e0fef82007-06-17 19:56:36 -0500270 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500271 lpfc_mbuf_free(phba, mp->virt, mp->phys);
272 kfree(mp);
273 pmb->context1 = NULL;
274
James Smarta12e07b2006-12-02 13:35:30 -0500275 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500276 u64_to_wwn(phba->cfg_soft_wwnn,
277 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400278 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500279 u64_to_wwn(phba->cfg_soft_wwpn,
280 vport->fc_sparam.portName.u.wwn);
281 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500282 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500283 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500284 sizeof (struct lpfc_name));
285 /* If no serial number in VPD data, use low 6 bytes of WWNN */
286 /* This should be consolidated into parse_vpd ? - mr */
287 if (phba->SerialNumber[0] == 0) {
288 uint8_t *outptr;
289
James Smart2e0fef82007-06-17 19:56:36 -0500290 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500291 for (i = 0; i < 12; i++) {
292 status = *outptr++;
293 j = ((status & 0xf0) >> 4);
294 if (j <= 9)
295 phba->SerialNumber[i] =
296 (char)((uint8_t) 0x30 + (uint8_t) j);
297 else
298 phba->SerialNumber[i] =
299 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
300 i++;
301 j = (status & 0xf);
302 if (j <= 9)
303 phba->SerialNumber[i] =
304 (char)((uint8_t) 0x30 + (uint8_t) j);
305 else
306 phba->SerialNumber[i] =
307 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
308 }
309 }
310
dea31012005-04-17 16:05:31 -0500311 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500312 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500313 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -0500315 "%d:0453 Adapter failed to init, mbxCmd x%x "
316 "READ_CONFIG, mbxStatus x%x\n",
317 phba->brd_no,
318 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500319 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500320 mempool_free( pmb, phba->mbox_mem_pool);
321 return -EIO;
322 }
323
324 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
325 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
326 phba->cfg_hba_queue_depth =
327 mb->un.varRdConfig.max_xri + 1;
328
329 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500330
331 /* Get the default values for Model Name and Description */
332 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
333
334 if ((phba->cfg_link_speed > LINK_SPEED_10G)
335 || ((phba->cfg_link_speed == LINK_SPEED_1G)
336 && !(phba->lmt & LMT_1Gb))
337 || ((phba->cfg_link_speed == LINK_SPEED_2G)
338 && !(phba->lmt & LMT_2Gb))
339 || ((phba->cfg_link_speed == LINK_SPEED_4G)
340 && !(phba->lmt & LMT_4Gb))
341 || ((phba->cfg_link_speed == LINK_SPEED_8G)
342 && !(phba->lmt & LMT_8Gb))
343 || ((phba->cfg_link_speed == LINK_SPEED_10G)
344 && !(phba->lmt & LMT_10Gb))) {
345 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500346 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -0500347 "%d:1302 Invalid speed for this board: "
348 "Reset link speed to auto: x%x\n",
349 phba->brd_no,
350 phba->cfg_link_speed);
351 phba->cfg_link_speed = LINK_SPEED_AUTO;
352 }
353
James Smart2e0fef82007-06-17 19:56:36 -0500354 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500355
356 /* Only process IOCBs on ring 0 till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500357 if (psli->ring[psli->extra_ring].cmdringaddr)
358 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500359 if (psli->ring[psli->fcp_ring].cmdringaddr)
360 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
361 if (psli->ring[psli->next_ring].cmdringaddr)
362 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
363
364 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500365 if (phba->sli_rev != 3)
366 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500367
368 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500369 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500370 status = readl(phba->HCregaddr);
371 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
372 if (psli->num_rings > 0)
373 status |= HC_R0INT_ENA;
374 if (psli->num_rings > 1)
375 status |= HC_R1INT_ENA;
376 if (psli->num_rings > 2)
377 status |= HC_R2INT_ENA;
378 if (psli->num_rings > 3)
379 status |= HC_R3INT_ENA;
380
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500381 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
382 (phba->cfg_poll & DISABLE_FCP_RING_INT))
383 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
384
dea31012005-04-17 16:05:31 -0500385 writel(status, phba->HCregaddr);
386 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500387 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500388
389 /*
390 * Setup the ring 0 (els) timeout handler
391 */
392 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500393 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart858c9f62007-06-17 19:56:39 -0500394 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
395 phba->hb_outstanding = 0;
396 phba->last_completion_time = jiffies;
dea31012005-04-17 16:05:31 -0500397
398 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
399 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500400 pmb->vport = vport;
James Smart8aee9182006-08-31 12:27:57 -0400401 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400402 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400403 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
dea31012005-04-17 16:05:31 -0500405 "%d:0454 Adapter failed to init, mbxCmd x%x "
406 "INIT_LINK, mbxStatus x%x\n",
407 phba->brd_no,
408 mb->mbxCommand, mb->mbxStatus);
409
410 /* Clear all interrupt enable conditions */
411 writel(0, phba->HCregaddr);
412 readl(phba->HCregaddr); /* flush */
413 /* Clear all pending interrupts */
414 writel(0xffffffff, phba->HAregaddr);
415 readl(phba->HAregaddr); /* flush */
416
James Smart2e0fef82007-06-17 19:56:36 -0500417 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400418 if (rc != MBX_BUSY)
419 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500420 return -EIO;
421 }
422 /* MBOX buffer will be freed in mbox compl */
423
James Smartce8b3ce2006-07-06 15:50:36 -0400424 return (0);
425}
426
dea31012005-04-17 16:05:31 -0500427/************************************************************************/
428/* */
429/* lpfc_hba_down_prep */
430/* This routine will do LPFC uninitialization before the */
431/* HBA is reset when bringing down the SLI Layer. This will be */
432/* initialized as a SLI layer callback routine. */
433/* This routine returns 0 on success. Any other return value */
434/* indicates an error. */
435/* */
436/************************************************************************/
437int
James Smart2e0fef82007-06-17 19:56:36 -0500438lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500439{
James Smart549e55c2007-08-02 11:09:51 -0400440 struct lpfc_vport **vports;
441 int i;
James Smart2e0fef82007-06-17 19:56:36 -0500442
dea31012005-04-17 16:05:31 -0500443 /* Disable interrupts */
444 writel(0, phba->HCregaddr);
445 readl(phba->HCregaddr); /* flush */
446
James Smart549e55c2007-08-02 11:09:51 -0400447 vports = lpfc_create_vport_work_array(phba);
448 if (vports != NULL)
449 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
450 lpfc_cleanup_discovery_resources(vports[i]);
451 lpfc_destroy_vport_work_array(vports);
James Smart2e0fef82007-06-17 19:56:36 -0500452 return 0;
dea31012005-04-17 16:05:31 -0500453}
454
455/************************************************************************/
456/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500457/* lpfc_hba_down_post */
458/* This routine will do uninitialization after the HBA is reset */
459/* when bringing down the SLI Layer. */
460/* This routine returns 0 on success. Any other return value */
461/* indicates an error. */
462/* */
463/************************************************************************/
464int
James Smart2e0fef82007-06-17 19:56:36 -0500465lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500466{
467 struct lpfc_sli *psli = &phba->sli;
468 struct lpfc_sli_ring *pring;
469 struct lpfc_dmabuf *mp, *next_mp;
470 int i;
471
James Smart92d7f7b2007-06-17 19:56:38 -0500472 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
473 lpfc_sli_hbqbuf_free_all(phba);
474 else {
475 /* Cleanup preposted buffers on the ELS ring */
476 pring = &psli->ring[LPFC_ELS_RING];
477 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
478 list_del(&mp->list);
479 pring->postbufq_cnt--;
480 lpfc_mbuf_free(phba, mp->virt, mp->phys);
481 kfree(mp);
482 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500483 }
484
485 for (i = 0; i < psli->num_rings; i++) {
486 pring = &psli->ring[i];
487 lpfc_sli_abort_iocb_ring(phba, pring);
488 }
489
490 return 0;
491}
492
James Smart858c9f62007-06-17 19:56:39 -0500493/* HBA heart beat timeout handler */
494void
495lpfc_hb_timeout(unsigned long ptr)
496{
497 struct lpfc_hba *phba;
498 unsigned long iflag;
499
500 phba = (struct lpfc_hba *)ptr;
501 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
502 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
503 phba->pport->work_port_events |= WORKER_HB_TMO;
504 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
505
506 if (phba->work_wait)
507 wake_up(phba->work_wait);
508 return;
509}
510
511static void
512lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
513{
514 unsigned long drvr_flag;
515
516 spin_lock_irqsave(&phba->hbalock, drvr_flag);
517 phba->hb_outstanding = 0;
518 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
519
520 mempool_free(pmboxq, phba->mbox_mem_pool);
521 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
522 !(phba->link_state == LPFC_HBA_ERROR) &&
523 !(phba->pport->fc_flag & FC_UNLOADING))
524 mod_timer(&phba->hb_tmofunc,
525 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
526 return;
527}
528
529void
530lpfc_hb_timeout_handler(struct lpfc_hba *phba)
531{
532 LPFC_MBOXQ_t *pmboxq;
533 int retval;
534 struct lpfc_sli *psli = &phba->sli;
535
536 if ((phba->link_state == LPFC_HBA_ERROR) ||
537 (phba->pport->fc_flag & FC_UNLOADING) ||
538 (phba->pport->fc_flag & FC_OFFLINE_MODE))
539 return;
540
541 spin_lock_irq(&phba->pport->work_port_lock);
542 /* If the timer is already canceled do nothing */
543 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
544 spin_unlock_irq(&phba->pport->work_port_lock);
545 return;
546 }
547
548 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
549 jiffies)) {
550 spin_unlock_irq(&phba->pport->work_port_lock);
551 if (!phba->hb_outstanding)
552 mod_timer(&phba->hb_tmofunc,
553 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
554 else
555 mod_timer(&phba->hb_tmofunc,
556 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
557 return;
558 }
559 spin_unlock_irq(&phba->pport->work_port_lock);
560
561 /* If there is no heart beat outstanding, issue a heartbeat command */
562 if (!phba->hb_outstanding) {
563 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
564 if (!pmboxq) {
565 mod_timer(&phba->hb_tmofunc,
566 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
567 return;
568 }
569
570 lpfc_heart_beat(phba, pmboxq);
571 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
572 pmboxq->vport = phba->pport;
573 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
574
575 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
576 mempool_free(pmboxq, phba->mbox_mem_pool);
577 mod_timer(&phba->hb_tmofunc,
578 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
579 return;
580 }
581 mod_timer(&phba->hb_tmofunc,
582 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
583 phba->hb_outstanding = 1;
584 return;
585 } else {
586 /*
587 * If heart beat timeout called with hb_outstanding set we
588 * need to take the HBA offline.
589 */
590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
591 "%d:0459 Adapter heartbeat failure, taking "
592 "this port offline.\n", phba->brd_no);
593
594 spin_lock_irq(&phba->hbalock);
595 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
596 spin_unlock_irq(&phba->hbalock);
597
598 lpfc_offline_prep(phba);
599 lpfc_offline(phba);
600 lpfc_unblock_mgmt_io(phba);
601 phba->link_state = LPFC_HBA_ERROR;
602 lpfc_hba_down_post(phba);
603 }
604}
605
Jamie Wellnitz41415862006-02-28 19:25:27 -0500606/************************************************************************/
607/* */
dea31012005-04-17 16:05:31 -0500608/* lpfc_handle_eratt */
609/* This routine will handle processing a Host Attention */
610/* Error Status event. This will be initialized */
611/* as a SLI layer callback routine. */
612/* */
613/************************************************************************/
614void
James Smart2e0fef82007-06-17 19:56:36 -0500615lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500616{
James Smart2e0fef82007-06-17 19:56:36 -0500617 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500618 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500619 struct lpfc_sli_ring *pring;
James Smart549e55c2007-08-02 11:09:51 -0400620 struct lpfc_vport **vports;
James Smartd2873e42006-08-18 17:46:43 -0400621 uint32_t event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500622 struct Scsi_Host *shost;
James Smart549e55c2007-08-02 11:09:51 -0400623 int i;
James Smart2e0fef82007-06-17 19:56:36 -0500624
Linas Vepstas8d63f372007-02-14 14:28:36 -0600625 /* If the pci channel is offline, ignore possible errors,
626 * since we cannot communicate with the pci card anyway. */
627 if (pci_channel_offline(phba->pcidev))
628 return;
dea31012005-04-17 16:05:31 -0500629
James Smartf5603512006-12-02 13:35:43 -0500630 if (phba->work_hs & HS_FFER6 ||
631 phba->work_hs & HS_FFER5) {
dea31012005-04-17 16:05:31 -0500632 /* Re-establishing Link */
633 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
634 "%d:1301 Re-establishing Link "
635 "Data: x%x x%x x%x\n",
636 phba->brd_no, phba->work_hs,
637 phba->work_status[0], phba->work_status[1]);
James Smart549e55c2007-08-02 11:09:51 -0400638 vports = lpfc_create_vport_work_array(phba);
639 if (vports != NULL)
640 for(i = 0;
641 i < LPFC_MAX_VPORTS && vports[i] != NULL;
642 i++){
643 shost = lpfc_shost_from_vport(vports[i]);
644 spin_lock_irq(shost->host_lock);
645 vports[i]->fc_flag |= FC_ESTABLISH_LINK;
646 spin_unlock_irq(shost->host_lock);
647 }
648 lpfc_destroy_vport_work_array(vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500649 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500650 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500651 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500652
653 /*
654 * Firmware stops when it triggled erratt with HS_FFER6.
655 * That could cause the I/Os dropped by the firmware.
656 * Error iocb (I/O) on txcmplq and let the SCSI layer
657 * retry it after re-establishing link.
658 */
659 pring = &psli->ring[psli->fcp_ring];
660 lpfc_sli_abort_iocb_ring(phba, pring);
661
662
663 /*
664 * There was a firmware error. Take the hba offline and then
665 * attempt to restart it.
666 */
James Smart46fa3112007-04-25 09:51:45 -0400667 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500668 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500669 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500670 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
671 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
James Smart46fa3112007-04-25 09:51:45 -0400672 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500673 return;
674 }
James Smart46fa3112007-04-25 09:51:45 -0400675 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500676 } else {
677 /* The if clause above forces this code path when the status
678 * failure is a value other than FFER6. Do not call the offline
679 * twice. This is the adapter hardware error path.
680 */
681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
682 "%d:0457 Adapter Hardware Error "
683 "Data: x%x x%x x%x\n",
684 phba->brd_no, phba->work_hs,
685 phba->work_status[0], phba->work_status[1]);
686
James Smartd2873e42006-08-18 17:46:43 -0400687 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -0500688 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -0500689 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400690 sizeof(event_data), (char *) &event_data,
691 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
692
James Smart92d7f7b2007-06-17 19:56:38 -0500693 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500694 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500695 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -0400696 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500697 lpfc_offline(phba);
James Smart46fa3112007-04-25 09:51:45 -0400698 lpfc_unblock_mgmt_io(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500699 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500700 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -0500701 }
702}
703
704/************************************************************************/
705/* */
706/* lpfc_handle_latt */
707/* This routine will handle processing a Host Attention */
708/* Link Status event. This will be initialized */
709/* as a SLI layer callback routine. */
710/* */
711/************************************************************************/
712void
James Smart2e0fef82007-06-17 19:56:36 -0500713lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500714{
James Smart2e0fef82007-06-17 19:56:36 -0500715 struct lpfc_vport *vport = phba->pport;
716 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500717 LPFC_MBOXQ_t *pmb;
718 volatile uint32_t control;
719 struct lpfc_dmabuf *mp;
720 int rc = -ENOMEM;
721
722 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
723 if (!pmb)
724 goto lpfc_handle_latt_err_exit;
725
726 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
727 if (!mp)
728 goto lpfc_handle_latt_free_pmb;
729
730 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
731 if (!mp->virt)
732 goto lpfc_handle_latt_free_mp;
733
734 rc = -EIO;
735
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500736 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -0400737 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -0500738
739 psli->slistat.link_event++;
740 lpfc_read_la(phba, pmb, mp);
741 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500742 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500743 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
744 if (rc == MBX_NOT_FINISHED)
James Smart14691152006-12-02 13:34:28 -0500745 goto lpfc_handle_latt_free_mbuf;
dea31012005-04-17 16:05:31 -0500746
747 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500748 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500749 writel(HA_LATT, phba->HAregaddr);
750 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500751 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500752
753 return;
754
James Smart14691152006-12-02 13:34:28 -0500755lpfc_handle_latt_free_mbuf:
756 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500757lpfc_handle_latt_free_mp:
758 kfree(mp);
759lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400760 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500761lpfc_handle_latt_err_exit:
762 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500763 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500764 psli->sli_flag |= LPFC_PROCESS_LA;
765 control = readl(phba->HCregaddr);
766 control |= HC_LAINT_ENA;
767 writel(control, phba->HCregaddr);
768 readl(phba->HCregaddr); /* flush */
769
770 /* Clear Link Attention in HA REG */
771 writel(HA_LATT, phba->HAregaddr);
772 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500773 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500774 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500775 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500776
777 /* The other case is an error from issue_mbox */
778 if (rc == -ENOMEM)
James Smarted957682007-06-17 19:56:37 -0500779 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
dea31012005-04-17 16:05:31 -0500780 "%d:0300 READ_LA: no buffers\n",
781 phba->brd_no);
782
783 return;
784}
785
786/************************************************************************/
787/* */
788/* lpfc_parse_vpd */
789/* This routine will parse the VPD data */
790/* */
791/************************************************************************/
792static int
James Smart2e0fef82007-06-17 19:56:36 -0500793lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500794{
795 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500796 int Length;
dea31012005-04-17 16:05:31 -0500797 int i, j;
798 int finished = 0;
799 int index = 0;
800
801 if (!vpd)
802 return 0;
803
804 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -0500805 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
dea31012005-04-17 16:05:31 -0500806 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
807 phba->brd_no,
808 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
809 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500810 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500811 switch (vpd[index]) {
812 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500813 case 0x91:
dea31012005-04-17 16:05:31 -0500814 index += 1;
815 lenlo = vpd[index];
816 index += 1;
817 lenhi = vpd[index];
818 index += 1;
819 i = ((((unsigned short)lenhi) << 8) + lenlo);
820 index += i;
821 break;
822 case 0x90:
823 index += 1;
824 lenlo = vpd[index];
825 index += 1;
826 lenhi = vpd[index];
827 index += 1;
828 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500829 if (Length > len - index)
830 Length = len - index;
dea31012005-04-17 16:05:31 -0500831 while (Length > 0) {
832 /* Look for Serial Number */
833 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
834 index += 2;
835 i = vpd[index];
836 index += 1;
837 j = 0;
838 Length -= (3+i);
839 while(i--) {
840 phba->SerialNumber[j++] = vpd[index++];
841 if (j == 31)
842 break;
843 }
844 phba->SerialNumber[j] = 0;
845 continue;
846 }
847 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
848 phba->vpd_flag |= VPD_MODEL_DESC;
849 index += 2;
850 i = vpd[index];
851 index += 1;
852 j = 0;
853 Length -= (3+i);
854 while(i--) {
855 phba->ModelDesc[j++] = vpd[index++];
856 if (j == 255)
857 break;
858 }
859 phba->ModelDesc[j] = 0;
860 continue;
861 }
862 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
863 phba->vpd_flag |= VPD_MODEL_NAME;
864 index += 2;
865 i = vpd[index];
866 index += 1;
867 j = 0;
868 Length -= (3+i);
869 while(i--) {
870 phba->ModelName[j++] = vpd[index++];
871 if (j == 79)
872 break;
873 }
874 phba->ModelName[j] = 0;
875 continue;
876 }
877 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
878 phba->vpd_flag |= VPD_PROGRAM_TYPE;
879 index += 2;
880 i = vpd[index];
881 index += 1;
882 j = 0;
883 Length -= (3+i);
884 while(i--) {
885 phba->ProgramType[j++] = vpd[index++];
886 if (j == 255)
887 break;
888 }
889 phba->ProgramType[j] = 0;
890 continue;
891 }
892 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
893 phba->vpd_flag |= VPD_PORT;
894 index += 2;
895 i = vpd[index];
896 index += 1;
897 j = 0;
898 Length -= (3+i);
899 while(i--) {
900 phba->Port[j++] = vpd[index++];
901 if (j == 19)
902 break;
903 }
904 phba->Port[j] = 0;
905 continue;
906 }
907 else {
908 index += 2;
909 i = vpd[index];
910 index += 1;
911 index += i;
912 Length -= (3 + i);
913 }
914 }
915 finished = 0;
916 break;
917 case 0x78:
918 finished = 1;
919 break;
920 default:
921 index ++;
922 break;
923 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500924 }
dea31012005-04-17 16:05:31 -0500925
926 return(1);
927}
928
929static void
James Smart2e0fef82007-06-17 19:56:36 -0500930lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -0500931{
932 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -0500933 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500934 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500935 struct {
936 char * name;
937 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500938 char * bus;
James Smart18a3b592006-12-02 13:35:08 -0500939 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500940
941 if (mdp && mdp[0] != '\0'
942 && descp && descp[0] != '\0')
943 return;
944
945 if (phba->lmt & LMT_10Gb)
946 max_speed = 10;
947 else if (phba->lmt & LMT_8Gb)
948 max_speed = 8;
949 else if (phba->lmt & LMT_4Gb)
950 max_speed = 4;
951 else if (phba->lmt & LMT_2Gb)
952 max_speed = 2;
953 else
954 max_speed = 1;
dea31012005-04-17 16:05:31 -0500955
956 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -0500957
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500958 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400959 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -0500960 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400961 break;
dea31012005-04-17 16:05:31 -0500962 case PCI_DEVICE_ID_SUPERFLY:
963 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -0500964 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500965 else
James Smart18a3b592006-12-02 13:35:08 -0500966 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500967 break;
968 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -0500969 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500970 break;
971 case PCI_DEVICE_ID_CENTAUR:
972 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -0500973 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500974 else
James Smart18a3b592006-12-02 13:35:08 -0500975 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500976 break;
977 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -0500978 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500979 break;
980 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -0500981 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500982 break;
983 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -0500984 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500985 break;
986 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -0500987 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500988 break;
989 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -0500990 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500991 break;
992 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -0500993 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500994 break;
995 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -0500996 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -0500997 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500998 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500999 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001000 break;
1001 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001002 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001003 break;
1004 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001005 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001006 break;
1007 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001008 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001009 break;
1010 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001011 m = (typeof(m)){"LPe1002-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_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001014 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001015 break;
1016 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001017 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001018 break;
1019 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001020 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001021 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001022 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001023 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001024 break;
1025 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001026 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001027 break;
dea31012005-04-17 16:05:31 -05001028 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001029 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001030 break;
1031 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001032 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001033 break;
1034 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001035 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001036 break;
1037 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001038 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001039 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001040 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001041 m = (typeof(m)){"LP11000-S", max_speed,
1042 "PCI-X2"};
1043 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001044 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001045 m = (typeof(m)){"LPe11000-S", max_speed,
1046 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001047 break;
James Smartb87eab32007-04-25 09:53:28 -04001048 case PCI_DEVICE_ID_SAT:
1049 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1050 break;
1051 case PCI_DEVICE_ID_SAT_MID:
1052 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1053 break;
1054 case PCI_DEVICE_ID_SAT_SMB:
1055 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1056 break;
1057 case PCI_DEVICE_ID_SAT_DCSP:
1058 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1059 break;
1060 case PCI_DEVICE_ID_SAT_SCSP:
1061 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1062 break;
1063 case PCI_DEVICE_ID_SAT_S:
1064 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1065 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001066 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001067 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001068 break;
dea31012005-04-17 16:05:31 -05001069 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001070
1071 if (mdp && mdp[0] == '\0')
1072 snprintf(mdp, 79,"%s", m.name);
1073 if (descp && descp[0] == '\0')
1074 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -05001075 "Emulex %s %dGb %s Fibre Channel Adapter",
1076 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -05001077}
1078
1079/**************************************************/
1080/* lpfc_post_buffer */
1081/* */
1082/* This routine will post count buffers to the */
1083/* ring with the QUE_RING_BUF_CN command. This */
1084/* allows 3 buffers / command to be posted. */
1085/* Returns the number of buffers NOT posted. */
1086/**************************************************/
1087int
James Smart2e0fef82007-06-17 19:56:36 -05001088lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -05001089 int type)
1090{
1091 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001092 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001093 struct lpfc_dmabuf *mp1, *mp2;
1094
1095 cnt += pring->missbufcnt;
1096
1097 /* While there are buffers to post */
1098 while (cnt > 0) {
1099 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001100 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001101 if (iocb == NULL) {
1102 pring->missbufcnt = cnt;
1103 return cnt;
1104 }
dea31012005-04-17 16:05:31 -05001105 icmd = &iocb->iocb;
1106
1107 /* 2 buffers can be posted per command */
1108 /* Allocate buffer to post */
1109 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1110 if (mp1)
1111 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1112 &mp1->phys);
1113 if (mp1 == 0 || mp1->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001114 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001115 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001116 pring->missbufcnt = cnt;
1117 return cnt;
1118 }
1119
1120 INIT_LIST_HEAD(&mp1->list);
1121 /* Allocate buffer to post */
1122 if (cnt > 1) {
1123 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1124 if (mp2)
1125 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1126 &mp2->phys);
1127 if (mp2 == 0 || mp2->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001128 kfree(mp2);
dea31012005-04-17 16:05:31 -05001129 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1130 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001131 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001132 pring->missbufcnt = cnt;
1133 return cnt;
1134 }
1135
1136 INIT_LIST_HEAD(&mp2->list);
1137 } else {
1138 mp2 = NULL;
1139 }
1140
1141 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1142 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1143 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1144 icmd->ulpBdeCount = 1;
1145 cnt--;
1146 if (mp2) {
1147 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1148 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1149 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1150 cnt--;
1151 icmd->ulpBdeCount = 2;
1152 }
1153
1154 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1155 icmd->ulpLe = 1;
1156
dea31012005-04-17 16:05:31 -05001157 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1158 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1159 kfree(mp1);
1160 cnt++;
1161 if (mp2) {
1162 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1163 kfree(mp2);
1164 cnt++;
1165 }
James Bottomley604a3e32005-10-29 10:28:33 -05001166 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001167 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001168 return cnt;
1169 }
dea31012005-04-17 16:05:31 -05001170 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001171 if (mp2)
dea31012005-04-17 16:05:31 -05001172 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001173 }
1174 pring->missbufcnt = 0;
1175 return 0;
1176}
1177
1178/************************************************************************/
1179/* */
1180/* lpfc_post_rcv_buf */
1181/* This routine post initial rcv buffers to the configured rings */
1182/* */
1183/************************************************************************/
1184static int
James Smart2e0fef82007-06-17 19:56:36 -05001185lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001186{
1187 struct lpfc_sli *psli = &phba->sli;
1188
1189 /* Ring 0, ELS / CT buffers */
1190 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1191 /* Ring 2 - FCP no buffers needed */
1192
1193 return 0;
1194}
1195
1196#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1197
1198/************************************************************************/
1199/* */
1200/* lpfc_sha_init */
1201/* */
1202/************************************************************************/
1203static void
1204lpfc_sha_init(uint32_t * HashResultPointer)
1205{
1206 HashResultPointer[0] = 0x67452301;
1207 HashResultPointer[1] = 0xEFCDAB89;
1208 HashResultPointer[2] = 0x98BADCFE;
1209 HashResultPointer[3] = 0x10325476;
1210 HashResultPointer[4] = 0xC3D2E1F0;
1211}
1212
1213/************************************************************************/
1214/* */
1215/* lpfc_sha_iterate */
1216/* */
1217/************************************************************************/
1218static void
1219lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1220{
1221 int t;
1222 uint32_t TEMP;
1223 uint32_t A, B, C, D, E;
1224 t = 16;
1225 do {
1226 HashWorkingPointer[t] =
1227 S(1,
1228 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1229 8] ^
1230 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1231 } while (++t <= 79);
1232 t = 0;
1233 A = HashResultPointer[0];
1234 B = HashResultPointer[1];
1235 C = HashResultPointer[2];
1236 D = HashResultPointer[3];
1237 E = HashResultPointer[4];
1238
1239 do {
1240 if (t < 20) {
1241 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1242 } else if (t < 40) {
1243 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1244 } else if (t < 60) {
1245 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1246 } else {
1247 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1248 }
1249 TEMP += S(5, A) + E + HashWorkingPointer[t];
1250 E = D;
1251 D = C;
1252 C = S(30, B);
1253 B = A;
1254 A = TEMP;
1255 } while (++t <= 79);
1256
1257 HashResultPointer[0] += A;
1258 HashResultPointer[1] += B;
1259 HashResultPointer[2] += C;
1260 HashResultPointer[3] += D;
1261 HashResultPointer[4] += E;
1262
1263}
1264
1265/************************************************************************/
1266/* */
1267/* lpfc_challenge_key */
1268/* */
1269/************************************************************************/
1270static void
1271lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1272{
1273 *HashWorking = (*RandomChallenge ^ *HashWorking);
1274}
1275
1276/************************************************************************/
1277/* */
1278/* lpfc_hba_init */
1279/* */
1280/************************************************************************/
1281void
1282lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1283{
1284 int t;
1285 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001286 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001287
1288 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1289 if (!HashWorking)
1290 return;
1291
1292 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1293 HashWorking[0] = HashWorking[78] = *pwwnn++;
1294 HashWorking[1] = HashWorking[79] = *pwwnn;
1295
1296 for (t = 0; t < 7; t++)
1297 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1298
1299 lpfc_sha_init(hbainit);
1300 lpfc_sha_iterate(hbainit, HashWorking);
1301 kfree(HashWorking);
1302}
1303
1304static void
James Smart2e0fef82007-06-17 19:56:36 -05001305lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001306{
1307 struct lpfc_nodelist *ndlp, *next_ndlp;
1308
1309 /* clean up phba - lpfc specific */
James Smart2e0fef82007-06-17 19:56:36 -05001310 lpfc_can_disctmo(vport);
1311 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart329f9bc2007-04-25 09:53:01 -04001312 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001313 return;
1314}
1315
1316static void
1317lpfc_establish_link_tmo(unsigned long ptr)
1318{
James Smart92d7f7b2007-06-17 19:56:38 -05001319 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
James Smart549e55c2007-08-02 11:09:51 -04001320 struct lpfc_vport **vports;
dea31012005-04-17 16:05:31 -05001321 unsigned long iflag;
James Smart549e55c2007-08-02 11:09:51 -04001322 int i;
dea31012005-04-17 16:05:31 -05001323
dea31012005-04-17 16:05:31 -05001324 /* Re-establishing Link, timer expired */
1325 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1326 "%d:1300 Re-establishing Link, timer expired "
1327 "Data: x%x x%x\n",
James Smart549e55c2007-08-02 11:09:51 -04001328 phba->brd_no, phba->pport->fc_flag,
1329 phba->pport->port_state);
1330 vports = lpfc_create_vport_work_array(phba);
1331 if (vports != NULL)
1332 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1333 struct Scsi_Host *shost;
1334 shost = lpfc_shost_from_vport(vports[i]);
1335 spin_lock_irqsave(shost->host_lock, iflag);
1336 vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
1337 spin_unlock_irqrestore(shost->host_lock, iflag);
1338 }
1339 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001340}
1341
James Smart92d7f7b2007-06-17 19:56:38 -05001342void
1343lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001344{
James Smart92d7f7b2007-06-17 19:56:38 -05001345 del_timer_sync(&vport->els_tmofunc);
1346 del_timer_sync(&vport->fc_fdmitmo);
1347 lpfc_can_disctmo(vport);
1348 return;
dea31012005-04-17 16:05:31 -05001349}
1350
James Smart2e0fef82007-06-17 19:56:36 -05001351static void
James Smart92d7f7b2007-06-17 19:56:38 -05001352lpfc_stop_phba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001353{
James Smart549e55c2007-08-02 11:09:51 -04001354 struct lpfc_vport **vports;
1355 int i;
dea31012005-04-17 16:05:31 -05001356
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001357 del_timer_sync(&phba->fcp_poll_timer);
dea31012005-04-17 16:05:31 -05001358 del_timer_sync(&phba->fc_estabtmo);
James Smart549e55c2007-08-02 11:09:51 -04001359 vports = lpfc_create_vport_work_array(phba);
1360 if (vports != NULL)
1361 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
1362 lpfc_stop_vport_timers(vports[i]);
1363 lpfc_destroy_vport_work_array(vports);
James Smart2e0fef82007-06-17 19:56:36 -05001364 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001365 del_timer_sync(&phba->fabric_block_timer);
James Smart858c9f62007-06-17 19:56:39 -05001366 phba->hb_outstanding = 0;
1367 del_timer_sync(&phba->hb_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05001368 return;
dea31012005-04-17 16:05:31 -05001369}
1370
1371int
James Smart2e0fef82007-06-17 19:56:36 -05001372lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001373{
James Smart2e0fef82007-06-17 19:56:36 -05001374 struct lpfc_vport *vport = phba->pport;
James Smart549e55c2007-08-02 11:09:51 -04001375 struct lpfc_vport **vports;
1376 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001377
dea31012005-04-17 16:05:31 -05001378 if (!phba)
1379 return 0;
1380
James Smart2e0fef82007-06-17 19:56:36 -05001381 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001382 return 0;
1383
James Smarted957682007-06-17 19:56:37 -05001384 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
dea31012005-04-17 16:05:31 -05001385 "%d:0458 Bring Adapter online\n",
1386 phba->brd_no);
1387
James Smart46fa3112007-04-25 09:51:45 -04001388 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001389
James Smart46fa3112007-04-25 09:51:45 -04001390 if (!lpfc_sli_queue_setup(phba)) {
1391 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001392 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001393 }
1394
1395 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1396 lpfc_unblock_mgmt_io(phba);
1397 return 1;
1398 }
dea31012005-04-17 16:05:31 -05001399
James Smart549e55c2007-08-02 11:09:51 -04001400 vports = lpfc_create_vport_work_array(phba);
1401 if (vports != NULL)
1402 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1403 struct Scsi_Host *shost;
1404 shost = lpfc_shost_from_vport(vports[i]);
1405 spin_lock_irq(shost->host_lock);
1406 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1407 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1408 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1409 spin_unlock_irq(shost->host_lock);
1410 }
1411 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001412
James Smart46fa3112007-04-25 09:51:45 -04001413 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001414 return 0;
1415}
1416
James Smart46fa3112007-04-25 09:51:45 -04001417void
1418lpfc_block_mgmt_io(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -05001419{
dea31012005-04-17 16:05:31 -05001420 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001421
James Smart2e0fef82007-06-17 19:56:36 -05001422 spin_lock_irqsave(&phba->hbalock, iflag);
1423 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1424 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001425}
1426
1427void
1428lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1429{
1430 unsigned long iflag;
1431
James Smart2e0fef82007-06-17 19:56:36 -05001432 spin_lock_irqsave(&phba->hbalock, iflag);
1433 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1434 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001435}
1436
1437void
1438lpfc_offline_prep(struct lpfc_hba * phba)
1439{
James Smart2e0fef82007-06-17 19:56:36 -05001440 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001441 struct lpfc_nodelist *ndlp, *next_ndlp;
dea31012005-04-17 16:05:31 -05001442
James Smart2e0fef82007-06-17 19:56:36 -05001443 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001444 return;
dea31012005-04-17 16:05:31 -05001445
James Smart46fa3112007-04-25 09:51:45 -04001446 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001447
1448 lpfc_linkdown(phba);
1449
James Smart46fa3112007-04-25 09:51:45 -04001450 /* Issue an unreg_login to all nodes */
James Smart2e0fef82007-06-17 19:56:36 -05001451 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart685f0bf2007-04-25 09:53:08 -04001452 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001453 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001454
James Smart46fa3112007-04-25 09:51:45 -04001455 lpfc_sli_flush_mbox_queue(phba);
1456}
1457
1458void
James Smart2e0fef82007-06-17 19:56:36 -05001459lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001460{
James Smart549e55c2007-08-02 11:09:51 -04001461 struct Scsi_Host *shost;
1462 struct lpfc_vport **vports;
1463 int i;
James Smart46fa3112007-04-25 09:51:45 -04001464
James Smart549e55c2007-08-02 11:09:51 -04001465 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001466 return;
James Smart688a8862006-07-06 15:49:56 -04001467
dea31012005-04-17 16:05:31 -05001468 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05001469 lpfc_stop_phba_timers(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001470 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
dea31012005-04-17 16:05:31 -05001471 "%d:0460 Bring Adapter offline\n",
1472 phba->brd_no);
dea31012005-04-17 16:05:31 -05001473 /* Bring down the SLI Layer and cleanup. The HBA is offline
1474 now. */
1475 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001476 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001477 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001478 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04001479 vports = lpfc_create_vport_work_array(phba);
1480 if (vports != NULL)
1481 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1482 shost = lpfc_shost_from_vport(vports[i]);
1483 lpfc_cleanup(vports[i]);
1484 spin_lock_irq(shost->host_lock);
1485 vports[i]->work_port_events = 0;
1486 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1487 spin_unlock_irq(shost->host_lock);
1488 }
1489 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -05001490}
1491
1492/******************************************************************************
1493* Function name: lpfc_scsi_free
1494*
1495* Description: Called from lpfc_pci_remove_one free internal driver resources
1496*
1497******************************************************************************/
1498static int
James Smart2e0fef82007-06-17 19:56:36 -05001499lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001500{
1501 struct lpfc_scsi_buf *sb, *sb_next;
1502 struct lpfc_iocbq *io, *io_next;
1503
James Smart2e0fef82007-06-17 19:56:36 -05001504 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001505 /* Release all the lpfc_scsi_bufs maintained by this host. */
1506 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1507 list_del(&sb->list);
1508 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05001509 sb->dma_handle);
dea31012005-04-17 16:05:31 -05001510 kfree(sb);
1511 phba->total_scsi_bufs--;
1512 }
1513
1514 /* Release all the lpfc_iocbq entries maintained by this host. */
1515 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1516 list_del(&io->list);
1517 kfree(io);
1518 phba->total_iocbq_bufs--;
1519 }
1520
James Smart2e0fef82007-06-17 19:56:36 -05001521 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001522
1523 return 0;
1524}
1525
James Smart2e0fef82007-06-17 19:56:36 -05001526struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05001527lpfc_create_port(struct lpfc_hba *phba, int instance, struct fc_vport *fc_vport)
James Smart47a86172007-04-25 09:53:22 -04001528{
James Smart2e0fef82007-06-17 19:56:36 -05001529 struct lpfc_vport *vport;
1530 struct Scsi_Host *shost;
1531 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001532
James Smart2e0fef82007-06-17 19:56:36 -05001533 shost = scsi_host_alloc(&lpfc_template, sizeof(struct lpfc_vport));
1534 if (!shost)
1535 goto out;
James Smart47a86172007-04-25 09:53:22 -04001536
James Smart2e0fef82007-06-17 19:56:36 -05001537 vport = (struct lpfc_vport *) shost->hostdata;
1538 vport->phba = phba;
James Smart47a86172007-04-25 09:53:22 -04001539
James Smart2e0fef82007-06-17 19:56:36 -05001540 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05001541 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart47a86172007-04-25 09:53:22 -04001542
James Smart2e0fef82007-06-17 19:56:36 -05001543 shost->unique_id = instance;
1544 shost->max_id = LPFC_MAX_TARGET;
1545 shost->max_lun = phba->cfg_max_luns;
1546 shost->this_id = -1;
1547 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001548 /*
James Smart2e0fef82007-06-17 19:56:36 -05001549 * Set initial can_queue value since 0 is no longer supported and
1550 * scsi_add_host will fail. This will be adjusted later based on the
1551 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001552 */
James Smart2e0fef82007-06-17 19:56:36 -05001553 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart92d7f7b2007-06-17 19:56:38 -05001554 if (fc_vport != NULL) {
1555 shost->transportt = lpfc_vport_transport_template;
1556 vport->port_type = LPFC_NPIV_PORT;
1557 } else {
1558 shost->transportt = lpfc_transport_template;
1559 vport->port_type = LPFC_PHYSICAL_PORT;
1560 }
James Smart47a86172007-04-25 09:53:22 -04001561
James Smart2e0fef82007-06-17 19:56:36 -05001562 /* Initialize all internally managed lists. */
1563 INIT_LIST_HEAD(&vport->fc_nodes);
1564 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001565
James Smart2e0fef82007-06-17 19:56:36 -05001566 init_timer(&vport->fc_disctmo);
1567 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001568 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001569
James Smart2e0fef82007-06-17 19:56:36 -05001570 init_timer(&vport->fc_fdmitmo);
1571 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05001572 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001573
James Smart2e0fef82007-06-17 19:56:36 -05001574 init_timer(&vport->els_tmofunc);
1575 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05001576 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04001577
James Smart92d7f7b2007-06-17 19:56:38 -05001578 if (fc_vport != NULL) {
1579 error = scsi_add_host(shost, &fc_vport->dev);
1580 } else {
1581 error = scsi_add_host(shost, &phba->pcidev->dev);
1582 }
James Smart2e0fef82007-06-17 19:56:36 -05001583 if (error)
1584 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001585
James Smart549e55c2007-08-02 11:09:51 -04001586 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001587 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04001588 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05001589 return vport;
James Smart47a86172007-04-25 09:53:22 -04001590
James Smart2e0fef82007-06-17 19:56:36 -05001591out_put_shost:
1592 scsi_host_put(shost);
1593out:
1594 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001595}
1596
James Smart2e0fef82007-06-17 19:56:36 -05001597void
1598destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001599{
James Smart92d7f7b2007-06-17 19:56:38 -05001600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1601 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001602
James Smart92d7f7b2007-06-17 19:56:38 -05001603 kfree(vport->vname);
James Smart47a86172007-04-25 09:53:22 -04001604
James Smart858c9f62007-06-17 19:56:39 -05001605 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001606 fc_remove_host(shost);
1607 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04001608
James Smart92d7f7b2007-06-17 19:56:38 -05001609 spin_lock_irq(&phba->hbalock);
1610 list_del_init(&vport->listentry);
1611 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04001612
James Smart92d7f7b2007-06-17 19:56:38 -05001613 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04001614 return;
James Smart47a86172007-04-25 09:53:22 -04001615}
1616
James Smart92d7f7b2007-06-17 19:56:38 -05001617int
1618lpfc_get_instance(void)
1619{
1620 int instance = 0;
1621
1622 /* Assign an unused number */
1623 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1624 return -1;
1625 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1626 return -1;
1627 return instance;
1628}
1629
James Smart858c9f62007-06-17 19:56:39 -05001630/*
1631 * Note: there is no scan_start function as adapter initialization
1632 * will have asynchronously kicked off the link initialization.
1633 */
James Smart47a86172007-04-25 09:53:22 -04001634
1635int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1636{
James Smart2e0fef82007-06-17 19:56:36 -05001637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1638 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05001639 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04001640
James Smart858c9f62007-06-17 19:56:39 -05001641 spin_lock_irq(shost->host_lock);
1642
1643 if (vport->fc_flag & FC_UNLOADING) {
1644 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001645 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05001646 }
James Smart2e0fef82007-06-17 19:56:36 -05001647 if (time >= 30 * HZ) {
1648 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1649 "%d:0461 Scanning longer than 30 "
1650 "seconds. Continuing initialization\n",
1651 phba->brd_no);
James Smart858c9f62007-06-17 19:56:39 -05001652 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001653 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001654 }
1655 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1656 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1657 "%d:0465 Link down longer than 15 "
1658 "seconds. Continuing initialization\n",
1659 phba->brd_no);
James Smart858c9f62007-06-17 19:56:39 -05001660 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001661 goto finished;
James Smart47a86172007-04-25 09:53:22 -04001662 }
1663
James Smart2e0fef82007-06-17 19:56:36 -05001664 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05001665 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001666 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05001667 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001668 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05001669 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001670 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05001671 goto finished;
1672
1673 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04001674
1675finished:
James Smart858c9f62007-06-17 19:56:39 -05001676 spin_unlock_irq(shost->host_lock);
1677 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05001678}
1679
1680void lpfc_host_attrib_init(struct Scsi_Host *shost)
1681{
1682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1683 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001684 /*
James Smart2e0fef82007-06-17 19:56:36 -05001685 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001686 */
1687
James Smart2e0fef82007-06-17 19:56:36 -05001688 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1689 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001690 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1691
1692 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001693 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001694 fc_host_supported_fc4s(shost)[2] = 1;
1695 fc_host_supported_fc4s(shost)[7] = 1;
1696
James Smart92d7f7b2007-06-17 19:56:38 -05001697 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1698 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04001699
1700 fc_host_supported_speeds(shost) = 0;
1701 if (phba->lmt & LMT_10Gb)
1702 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1703 if (phba->lmt & LMT_4Gb)
1704 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1705 if (phba->lmt & LMT_2Gb)
1706 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1707 if (phba->lmt & LMT_1Gb)
1708 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1709
1710 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001711 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1712 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001713
1714 /* This value is also unchanging */
1715 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001716 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001717 fc_host_active_fc4s(shost)[2] = 1;
1718 fc_host_active_fc4s(shost)[7] = 1;
1719
James Smart92d7f7b2007-06-17 19:56:38 -05001720 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04001721 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001722 vport->fc_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001723 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04001724}
dea31012005-04-17 16:05:31 -05001725
1726static int __devinit
1727lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1728{
James Smart2e0fef82007-06-17 19:56:36 -05001729 struct lpfc_vport *vport = NULL;
1730 struct lpfc_hba *phba;
1731 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001732 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001733 struct Scsi_Host *shost = NULL;
dea31012005-04-17 16:05:31 -05001734 unsigned long bar0map_len, bar2map_len;
James Bottomleya5785032007-07-14 18:47:04 -05001735 int error = -ENODEV;
dea31012005-04-17 16:05:31 -05001736 int i;
James Bottomley604a3e32005-10-29 10:28:33 -05001737 uint16_t iotag;
dea31012005-04-17 16:05:31 -05001738
1739 if (pci_enable_device(pdev))
1740 goto out;
1741 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1742 goto out_disable_device;
1743
James Smart2e0fef82007-06-17 19:56:36 -05001744 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1745 if (!phba)
dea31012005-04-17 16:05:31 -05001746 goto out_release_regions;
1747
James Smart2e0fef82007-06-17 19:56:36 -05001748 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001749
dea31012005-04-17 16:05:31 -05001750 phba->pcidev = pdev;
1751
1752 /* Assign an unused board number */
James Smart92d7f7b2007-06-17 19:56:38 -05001753 if ((phba->brd_no = lpfc_get_instance()) < 0)
James Smart2e0fef82007-06-17 19:56:36 -05001754 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001755
James Smart2e0fef82007-06-17 19:56:36 -05001756 INIT_LIST_HEAD(&phba->port_list);
James Smart92d7f7b2007-06-17 19:56:38 -05001757 INIT_LIST_HEAD(&phba->hbq_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05001758 /*
1759 * Get all the module params for configuring this host and then
1760 * establish the host.
1761 */
1762 lpfc_get_cfgparam(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001763 phba->max_vpi = LPFC_MAX_VPI;
dea31012005-04-17 16:05:31 -05001764
1765 /* Initialize timers used by driver */
1766 init_timer(&phba->fc_estabtmo);
1767 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1768 phba->fc_estabtmo.data = (unsigned long)phba;
dea31012005-04-17 16:05:31 -05001769
James Smart858c9f62007-06-17 19:56:39 -05001770 init_timer(&phba->hb_tmofunc);
1771 phba->hb_tmofunc.function = lpfc_hb_timeout;
1772 phba->hb_tmofunc.data = (unsigned long)phba;
1773
dea31012005-04-17 16:05:31 -05001774 psli = &phba->sli;
1775 init_timer(&psli->mbox_tmo);
1776 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001777 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001778 init_timer(&phba->fcp_poll_timer);
1779 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001780 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001781 init_timer(&phba->fabric_block_timer);
1782 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1783 phba->fabric_block_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001784
dea31012005-04-17 16:05:31 -05001785 pci_set_master(pdev);
Randy Dunlap694625c2007-07-09 11:55:54 -07001786 pci_try_set_mwi(pdev);
dea31012005-04-17 16:05:31 -05001787
1788 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1789 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1790 goto out_idr_remove;
1791
1792 /*
1793 * Get the bus address of Bar0 and Bar2 and the number of bytes
1794 * required by each mapping.
1795 */
1796 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1797 bar0map_len = pci_resource_len(phba->pcidev, 0);
1798
1799 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1800 bar2map_len = pci_resource_len(phba->pcidev, 2);
1801
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001802 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001803 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001804 if (!phba->slim_memmap_p) {
1805 error = -ENODEV;
1806 dev_printk(KERN_ERR, &pdev->dev,
1807 "ioremap failed for SLIM memory.\n");
1808 goto out_idr_remove;
1809 }
1810
1811 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001812 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001813 if (!phba->ctrl_regs_memmap_p) {
1814 error = -ENODEV;
1815 dev_printk(KERN_ERR, &pdev->dev,
1816 "ioremap failed for HBA control registers.\n");
1817 goto out_iounmap_slim;
1818 }
dea31012005-04-17 16:05:31 -05001819
1820 /* Allocate memory for SLI-2 structures */
1821 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1822 &phba->slim2p_mapping, GFP_KERNEL);
1823 if (!phba->slim2p)
1824 goto out_iounmap;
1825
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001826 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05001827
James Smarted957682007-06-17 19:56:37 -05001828 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1829 lpfc_sli_hbq_size(),
1830 &phba->hbqslimp.phys,
1831 GFP_KERNEL);
1832 if (!phba->hbqslimp.virt)
1833 goto out_free_slim;
1834
1835 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
1836
dea31012005-04-17 16:05:31 -05001837 /* Initialize the SLI Layer to run with lpfc HBAs. */
1838 lpfc_sli_setup(phba);
1839 lpfc_sli_queue_setup(phba);
1840
1841 error = lpfc_mem_alloc(phba);
1842 if (error)
James Smarted957682007-06-17 19:56:37 -05001843 goto out_free_hbqslimp;
dea31012005-04-17 16:05:31 -05001844
1845 /* Initialize and populate the iocb list per host. */
1846 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1847 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001848 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001849 if (iocbq_entry == NULL) {
1850 printk(KERN_ERR "%s: only allocated %d iocbs of "
1851 "expected %d count. Unloading driver.\n",
1852 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1853 error = -ENOMEM;
1854 goto out_free_iocbq;
1855 }
1856
James Bottomley604a3e32005-10-29 10:28:33 -05001857 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1858 if (iotag == 0) {
1859 kfree (iocbq_entry);
1860 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1861 "Unloading driver.\n",
1862 __FUNCTION__);
1863 error = -ENOMEM;
1864 goto out_free_iocbq;
1865 }
James Smart2e0fef82007-06-17 19:56:36 -05001866
1867 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001868 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1869 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05001870 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001871 }
1872
1873 /* Initialize HBA structure */
1874 phba->fc_edtov = FF_DEF_EDTOV;
1875 phba->fc_ratov = FF_DEF_RATOV;
1876 phba->fc_altov = FF_DEF_ALTOV;
1877 phba->fc_arbtov = FF_DEF_ARBTOV;
1878
1879 INIT_LIST_HEAD(&phba->work_list);
1880 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1881 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1882
1883 /* Startup the kernel thread for this host adapter. */
1884 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1885 "lpfc_worker_%d", phba->brd_no);
1886 if (IS_ERR(phba->worker_thread)) {
1887 error = PTR_ERR(phba->worker_thread);
1888 goto out_free_iocbq;
1889 }
1890
dea31012005-04-17 16:05:31 -05001891 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001892 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05001893 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1894
James Smart92d7f7b2007-06-17 19:56:38 -05001895 /* Initialize list of fabric iocbs */
1896 INIT_LIST_HEAD(&phba->fabric_iocb_list);
1897
1898 vport = lpfc_create_port(phba, phba->brd_no, NULL);
James Smart2e0fef82007-06-17 19:56:36 -05001899 if (!vport)
1900 goto out_kthread_stop;
1901
1902 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001903 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05001904 lpfc_debugfs_initialize(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001905
James Smart92d7f7b2007-06-17 19:56:38 -05001906 pci_set_drvdata(pdev, shost);
dea31012005-04-17 16:05:31 -05001907
James Smart4ff43242006-12-02 13:34:56 -05001908 if (phba->cfg_use_msi) {
1909 error = pci_enable_msi(phba->pcidev);
1910 if (error)
1911 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "%d:0452 "
1912 "Enable MSI failed, continuing with "
1913 "IRQ\n", phba->brd_no);
1914 }
1915
Thomas Gleixner1d6f3592006-07-01 19:29:42 -07001916 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
James Smart2e0fef82007-06-17 19:56:36 -05001917 LPFC_DRIVER_NAME, phba);
dea31012005-04-17 16:05:31 -05001918 if (error) {
1919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1920 "%d:0451 Enable interrupt handler failed\n",
1921 phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -05001922 goto out_disable_msi;
dea31012005-04-17 16:05:31 -05001923 }
dea31012005-04-17 16:05:31 -05001924
James Smart2e0fef82007-06-17 19:56:36 -05001925 phba->MBslimaddr = phba->slim_memmap_p;
1926 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1927 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1928 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1929 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1930
James Smart92d7f7b2007-06-17 19:56:38 -05001931 if (lpfc_alloc_sysfs_attr(vport))
dea31012005-04-17 16:05:31 -05001932 goto out_free_irq;
1933
James Smart858c9f62007-06-17 19:56:39 -05001934 if (lpfc_sli_hba_setup(phba))
1935 goto out_remove_device;
1936
1937 /*
1938 * hba setup may have changed the hba_queue_depth so we need to adjust
1939 * the value of can_queue.
1940 */
1941 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1942
1943 lpfc_host_attrib_init(shost);
1944
James Smart2e0fef82007-06-17 19:56:36 -05001945 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1946 spin_lock_irq(shost->host_lock);
1947 lpfc_poll_start_timer(phba);
1948 spin_unlock_irq(shost->host_lock);
1949 }
James Smart8f6d98d2006-08-01 07:34:00 -04001950
James Smart858c9f62007-06-17 19:56:39 -05001951 scsi_scan_host(shost);
dea31012005-04-17 16:05:31 -05001952
dea31012005-04-17 16:05:31 -05001953 return 0;
1954
James Smart858c9f62007-06-17 19:56:39 -05001955out_remove_device:
1956 lpfc_free_sysfs_attr(vport);
1957 spin_lock_irq(shost->host_lock);
1958 vport->fc_flag |= FC_UNLOADING;
1959 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960out_free_irq:
James Smart92d7f7b2007-06-17 19:56:38 -05001961 lpfc_stop_phba_timers(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001962 phba->pport->work_port_events = 0;
dea31012005-04-17 16:05:31 -05001963 free_irq(phba->pcidev->irq, phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001964out_disable_msi:
James Smart4ff43242006-12-02 13:34:56 -05001965 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05001966 destroy_port(vport);
dea31012005-04-17 16:05:31 -05001967out_kthread_stop:
1968 kthread_stop(phba->worker_thread);
1969out_free_iocbq:
1970 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1971 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05001972 kfree(iocbq_entry);
1973 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05001974 }
1975 lpfc_mem_free(phba);
James Smarted957682007-06-17 19:56:37 -05001976out_free_hbqslimp:
1977 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
1978 phba->hbqslimp.phys);
dea31012005-04-17 16:05:31 -05001979out_free_slim:
1980 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1981 phba->slim2p_mapping);
1982out_iounmap:
1983 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001984out_iounmap_slim:
dea31012005-04-17 16:05:31 -05001985 iounmap(phba->slim_memmap_p);
1986out_idr_remove:
1987 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05001988out_free_phba:
1989 kfree(phba);
dea31012005-04-17 16:05:31 -05001990out_release_regions:
1991 pci_release_regions(pdev);
1992out_disable_device:
1993 pci_disable_device(pdev);
1994out:
James Smartdefbcf12006-04-16 22:26:50 -04001995 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05001996 if (shost)
1997 scsi_host_put(shost);
dea31012005-04-17 16:05:31 -05001998 return error;
1999}
2000
2001static void __devexit
2002lpfc_pci_remove_one(struct pci_dev *pdev)
2003{
James Smart2e0fef82007-06-17 19:56:36 -05002004 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2006 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002007 struct lpfc_vport *port_iterator;
James Smart549e55c2007-08-02 11:09:51 -04002008 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05002009 list_for_each_entry(port_iterator, &phba->port_list, listentry)
2010 port_iterator->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04002011 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002012
James Smart858c9f62007-06-17 19:56:39 -05002013 kfree(vport->vname);
2014 lpfc_free_sysfs_attr(vport);
2015
2016 fc_remove_host(shost);
2017 scsi_remove_host(shost);
2018
James Smart2e0fef82007-06-17 19:56:36 -05002019 /*
2020 * Bring down the SLI Layer. This step disable all interrupts,
2021 * clears the rings, discards all mailbox commands, and resets
2022 * the HBA.
2023 */
2024 lpfc_sli_hba_down(phba);
2025 lpfc_sli_brdrestart(phba);
2026
James Smart92d7f7b2007-06-17 19:56:38 -05002027 lpfc_stop_phba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05002028 spin_lock_irq(&phba->hbalock);
2029 list_del_init(&vport->listentry);
2030 spin_unlock_irq(&phba->hbalock);
2031
James Smart858c9f62007-06-17 19:56:39 -05002032 lpfc_debugfs_terminate(vport);
2033 lpfc_cleanup(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002034
2035 kthread_stop(phba->worker_thread);
2036
2037 /* Release the irq reservation */
2038 free_irq(phba->pcidev->irq, phba);
2039 pci_disable_msi(phba->pcidev);
dea31012005-04-17 16:05:31 -05002040
2041 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05002042 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05002043
2044 /*
2045 * Call scsi_free before mem_free since scsi bufs are released to their
2046 * corresponding pools here.
2047 */
2048 lpfc_scsi_free(phba);
2049 lpfc_mem_free(phba);
2050
James Smarted957682007-06-17 19:56:37 -05002051 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2052 phba->hbqslimp.phys);
2053
James Smart2e0fef82007-06-17 19:56:36 -05002054 /* Free resources associated with SLI2 interface */
2055 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2056 phba->slim2p, phba->slim2p_mapping);
2057
2058 /* unmap adapter SLIM and Control Registers */
2059 iounmap(phba->ctrl_regs_memmap_p);
2060 iounmap(phba->slim_memmap_p);
2061
2062 idr_remove(&lpfc_hba_index, phba->brd_no);
2063
2064 kfree(phba);
2065
2066 pci_release_regions(pdev);
2067 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05002068}
2069
Linas Vepstas8d63f372007-02-14 14:28:36 -06002070/**
2071 * lpfc_io_error_detected - called when PCI error is detected
2072 * @pdev: Pointer to PCI device
2073 * @state: The current pci conneection state
2074 *
2075 * This function is called after a PCI bus error affecting
2076 * this device has been detected.
2077 */
2078static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2079 pci_channel_state_t state)
2080{
2081 struct Scsi_Host *host = pci_get_drvdata(pdev);
2082 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2083 struct lpfc_sli *psli = &phba->sli;
2084 struct lpfc_sli_ring *pring;
2085
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002086 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06002087 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06002088
Linas Vepstas8d63f372007-02-14 14:28:36 -06002089 pci_disable_device(pdev);
2090 /*
2091 * There may be I/Os dropped by the firmware.
2092 * Error iocb (I/O) on txcmplq and let the SCSI layer
2093 * retry it after re-establishing link.
2094 */
2095 pring = &psli->ring[psli->fcp_ring];
2096 lpfc_sli_abort_iocb_ring(phba, pring);
2097
2098 /* Request a slot reset. */
2099 return PCI_ERS_RESULT_NEED_RESET;
2100}
2101
2102/**
2103 * lpfc_io_slot_reset - called after the pci bus has been reset.
2104 * @pdev: Pointer to PCI device
2105 *
2106 * Restart the card from scratch, as if from a cold-boot.
2107 */
2108static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2109{
2110 struct Scsi_Host *host = pci_get_drvdata(pdev);
2111 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2112 struct lpfc_sli *psli = &phba->sli;
2113 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2114
2115 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2116 if (pci_enable_device_bars(pdev, bars)) {
2117 printk(KERN_ERR "lpfc: Cannot re-enable "
2118 "PCI device after reset.\n");
2119 return PCI_ERS_RESULT_DISCONNECT;
2120 }
2121
2122 pci_set_master(pdev);
2123
2124 /* Re-establishing Link */
James Smart2e0fef82007-06-17 19:56:36 -05002125 spin_lock_irq(host->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002126 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
James Smart2e0fef82007-06-17 19:56:36 -05002127 spin_unlock_irq(host->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002128
James Smart92d7f7b2007-06-17 19:56:38 -05002129 spin_lock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002130 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05002131 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06002132
2133
2134 /* Take device offline; this will perform cleanup */
2135 lpfc_offline(phba);
2136 lpfc_sli_brdrestart(phba);
2137
2138 return PCI_ERS_RESULT_RECOVERED;
2139}
2140
2141/**
2142 * lpfc_io_resume - called when traffic can start flowing again.
2143 * @pdev: Pointer to PCI device
2144 *
2145 * This callback is called when the error recovery driver tells us that
2146 * its OK to resume normal operation.
2147 */
2148static void lpfc_io_resume(struct pci_dev *pdev)
2149{
2150 struct Scsi_Host *host = pci_get_drvdata(pdev);
2151 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
2152
2153 if (lpfc_online(phba) == 0) {
2154 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2155 }
2156}
2157
dea31012005-04-17 16:05:31 -05002158static struct pci_device_id lpfc_id_table[] = {
2159 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2160 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002161 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2162 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002163 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2164 PCI_ANY_ID, PCI_ANY_ID, },
2165 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2166 PCI_ANY_ID, PCI_ANY_ID, },
2167 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2168 PCI_ANY_ID, PCI_ANY_ID, },
2169 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2170 PCI_ANY_ID, PCI_ANY_ID, },
2171 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2172 PCI_ANY_ID, PCI_ANY_ID, },
2173 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2174 PCI_ANY_ID, PCI_ANY_ID, },
2175 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2176 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002177 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2178 PCI_ANY_ID, PCI_ANY_ID, },
2179 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2180 PCI_ANY_ID, PCI_ANY_ID, },
2181 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2182 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002183 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2184 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002185 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2186 PCI_ANY_ID, PCI_ANY_ID, },
2187 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2188 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002189 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2190 PCI_ANY_ID, PCI_ANY_ID, },
2191 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2192 PCI_ANY_ID, PCI_ANY_ID, },
2193 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2194 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002195 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2196 PCI_ANY_ID, PCI_ANY_ID, },
2197 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2198 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002199 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2200 PCI_ANY_ID, PCI_ANY_ID, },
2201 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2202 PCI_ANY_ID, PCI_ANY_ID, },
2203 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2204 PCI_ANY_ID, PCI_ANY_ID, },
2205 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2206 PCI_ANY_ID, PCI_ANY_ID, },
2207 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2208 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002209 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2210 PCI_ANY_ID, PCI_ANY_ID, },
2211 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2212 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04002213 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2214 PCI_ANY_ID, PCI_ANY_ID, },
2215 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2216 PCI_ANY_ID, PCI_ANY_ID, },
2217 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2218 PCI_ANY_ID, PCI_ANY_ID, },
2219 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2220 PCI_ANY_ID, PCI_ANY_ID, },
2221 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2222 PCI_ANY_ID, PCI_ANY_ID, },
2223 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2224 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05002225 { 0 }
2226};
2227
2228MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2229
Linas Vepstas8d63f372007-02-14 14:28:36 -06002230static struct pci_error_handlers lpfc_err_handler = {
2231 .error_detected = lpfc_io_error_detected,
2232 .slot_reset = lpfc_io_slot_reset,
2233 .resume = lpfc_io_resume,
2234};
2235
dea31012005-04-17 16:05:31 -05002236static struct pci_driver lpfc_driver = {
2237 .name = LPFC_DRIVER_NAME,
2238 .id_table = lpfc_id_table,
2239 .probe = lpfc_pci_probe_one,
2240 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002241 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002242};
2243
2244static int __init
2245lpfc_init(void)
2246{
2247 int error = 0;
2248
2249 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002250 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002251
2252 lpfc_transport_template =
2253 fc_attach_transport(&lpfc_transport_functions);
James Smart92d7f7b2007-06-17 19:56:38 -05002254 lpfc_vport_transport_template =
2255 fc_attach_transport(&lpfc_vport_transport_functions);
2256 if (!lpfc_transport_template || !lpfc_vport_transport_template)
dea31012005-04-17 16:05:31 -05002257 return -ENOMEM;
2258 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05002259 if (error) {
dea31012005-04-17 16:05:31 -05002260 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002261 fc_release_transport(lpfc_vport_transport_template);
2262 }
dea31012005-04-17 16:05:31 -05002263
2264 return error;
2265}
2266
2267static void __exit
2268lpfc_exit(void)
2269{
2270 pci_unregister_driver(&lpfc_driver);
2271 fc_release_transport(lpfc_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05002272 fc_release_transport(lpfc_vport_transport_template);
dea31012005-04-17 16:05:31 -05002273}
2274
2275module_init(lpfc_init);
2276module_exit(lpfc_exit);
2277MODULE_LICENSE("GPL");
2278MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2279MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2280MODULE_VERSION("0:" LPFC_DRIVER_VERSION);