blob: e11c4cda0f3fad41dc6b9ec084ba9779c4b6d374 [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>
30
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_transport_fc.h>
35
36#include "lpfc_hw.h"
37#include "lpfc_sli.h"
38#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
43#include "lpfc_version.h"
44
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050045static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050046static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
47static int lpfc_post_rcv_buf(struct lpfc_hba *);
48
49static struct scsi_transport_template *lpfc_transport_template = NULL;
50static DEFINE_IDR(lpfc_hba_index);
51
James Smart2e0fef82007-06-17 19:56:36 -050052
53
dea31012005-04-17 16:05:31 -050054/************************************************************************/
55/* */
56/* lpfc_config_port_prep */
57/* This routine will do LPFC initialization prior to the */
58/* CONFIG_PORT mailbox command. This will be initialized */
59/* as a SLI layer callback routine. */
60/* This routine returns 0 on success or -ERESTART if it wants */
61/* the SLI layer to reset the HBA and try again. Any */
62/* other return value indicates an error. */
63/* */
64/************************************************************************/
65int
James Smart2e0fef82007-06-17 19:56:36 -050066lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050067{
68 lpfc_vpd_t *vp = &phba->vpd;
69 int i = 0, rc;
70 LPFC_MBOXQ_t *pmb;
71 MAILBOX_t *mb;
72 char *lpfc_vpd_data = NULL;
73 uint16_t offset = 0;
74 static char licensed[56] =
75 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040076 static int init_key = 1;
dea31012005-04-17 16:05:31 -050077
78 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
79 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050080 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050081 return -ENOMEM;
82 }
83
84 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050085 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050086
87 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040088 if (init_key) {
89 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -050090
James Smart65a29c12006-07-06 15:50:50 -040091 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
92 *ptext = cpu_to_be32(*ptext);
93 init_key = 0;
94 }
dea31012005-04-17 16:05:31 -050095
96 lpfc_read_nv(phba, pmb);
97 memset((char*)mb->un.varRDnvp.rsvd3, 0,
98 sizeof (mb->un.varRDnvp.rsvd3));
99 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
100 sizeof (licensed));
101
102 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
103
104 if (rc != MBX_SUCCESS) {
105 lpfc_printf_log(phba,
106 KERN_ERR,
107 LOG_MBOX,
108 "%d:0324 Config Port initialization "
109 "error, mbxCmd x%x READ_NVPARM, "
110 "mbxStatus x%x\n",
111 phba->brd_no,
112 mb->mbxCommand, mb->mbxStatus);
113 mempool_free(pmb, phba->mbox_mem_pool);
114 return -ERESTART;
115 }
116 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500117 sizeof(phba->wwnn));
118 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
119 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500120 }
121
122 /* Setup and issue mailbox READ REV command */
123 lpfc_read_rev(phba, pmb);
124 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
125 if (rc != MBX_SUCCESS) {
126 lpfc_printf_log(phba,
127 KERN_ERR,
128 LOG_INIT,
129 "%d:0439 Adapter failed to init, mbxCmd x%x "
130 "READ_REV, mbxStatus x%x\n",
131 phba->brd_no,
132 mb->mbxCommand, mb->mbxStatus);
133 mempool_free( pmb, phba->mbox_mem_pool);
134 return -ERESTART;
135 }
136
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500137 /*
138 * The value of rr must be 1 since the driver set the cv field to 1.
139 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500140 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500141 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500142 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
144 "%d:0440 Adapter failed to init, READ_REV has "
145 "missing revision information.\n",
146 phba->brd_no);
dea31012005-04-17 16:05:31 -0500147 mempool_free(pmb, phba->mbox_mem_pool);
148 return -ERESTART;
dea31012005-04-17 16:05:31 -0500149 }
150
151 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500152 vp->rev.rBit = 1;
153 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
154 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
155 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
156 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500157 vp->rev.biuRev = mb->un.varRdRev.biuRev;
158 vp->rev.smRev = mb->un.varRdRev.smRev;
159 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
160 vp->rev.endecRev = mb->un.varRdRev.endecRev;
161 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
162 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
163 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
164 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
165 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
166 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
167
168 if (lpfc_is_LC_HBA(phba->pcidev->device))
169 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
170 sizeof (phba->RandomData));
171
dea31012005-04-17 16:05:31 -0500172 /* Get adapter VPD information */
173 pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
174 if (!pmb->context2)
175 goto out_free_mbox;
176 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
177 if (!lpfc_vpd_data)
178 goto out_free_context2;
179
180 do {
181 lpfc_dump_mem(phba, pmb, offset);
182 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
183
184 if (rc != MBX_SUCCESS) {
185 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
186 "%d:0441 VPD not present on adapter, "
187 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
188 phba->brd_no,
189 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500190 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500191 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500192 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
193 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
dea31012005-04-17 16:05:31 -0500194 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
195 mb->un.varDmp.word_cnt);
196 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500197 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
198 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500199
200 kfree(lpfc_vpd_data);
201out_free_context2:
202 kfree(pmb->context2);
203out_free_mbox:
204 mempool_free(pmb, phba->mbox_mem_pool);
205 return 0;
206}
207
208/************************************************************************/
209/* */
210/* lpfc_config_port_post */
211/* This routine will do LPFC initialization after the */
212/* CONFIG_PORT mailbox command. This will be initialized */
213/* as a SLI layer callback routine. */
214/* This routine returns 0 on success. Any other return value */
215/* indicates an error. */
216/* */
217/************************************************************************/
218int
James Smart2e0fef82007-06-17 19:56:36 -0500219lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500220{
James Smart2e0fef82007-06-17 19:56:36 -0500221 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500222 LPFC_MBOXQ_t *pmb;
223 MAILBOX_t *mb;
224 struct lpfc_dmabuf *mp;
225 struct lpfc_sli *psli = &phba->sli;
226 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500227 int i, j;
228 int rc;
dea31012005-04-17 16:05:31 -0500229
230 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
231 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500232 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500233 return -ENOMEM;
234 }
235 mb = &pmb->mb;
236
dea31012005-04-17 16:05:31 -0500237 /* Get login parameters for NID. */
238 lpfc_read_sparam(phba, pmb);
239 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
240 lpfc_printf_log(phba,
241 KERN_ERR,
242 LOG_INIT,
243 "%d:0448 Adapter failed init, mbxCmd x%x "
244 "READ_SPARM mbxStatus x%x\n",
245 phba->brd_no,
246 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500247 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500248 mp = (struct lpfc_dmabuf *) pmb->context1;
249 mempool_free( pmb, phba->mbox_mem_pool);
250 lpfc_mbuf_free(phba, mp->virt, mp->phys);
251 kfree(mp);
252 return -EIO;
253 }
254
255 mp = (struct lpfc_dmabuf *) pmb->context1;
256
James Smart2e0fef82007-06-17 19:56:36 -0500257 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500258 lpfc_mbuf_free(phba, mp->virt, mp->phys);
259 kfree(mp);
260 pmb->context1 = NULL;
261
James Smarta12e07b2006-12-02 13:35:30 -0500262 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500263 u64_to_wwn(phba->cfg_soft_wwnn,
264 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400265 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500266 u64_to_wwn(phba->cfg_soft_wwpn,
267 vport->fc_sparam.portName.u.wwn);
268 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500269 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500270 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500271 sizeof (struct lpfc_name));
272 /* If no serial number in VPD data, use low 6 bytes of WWNN */
273 /* This should be consolidated into parse_vpd ? - mr */
274 if (phba->SerialNumber[0] == 0) {
275 uint8_t *outptr;
276
James Smart2e0fef82007-06-17 19:56:36 -0500277 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500278 for (i = 0; i < 12; i++) {
279 status = *outptr++;
280 j = ((status & 0xf0) >> 4);
281 if (j <= 9)
282 phba->SerialNumber[i] =
283 (char)((uint8_t) 0x30 + (uint8_t) j);
284 else
285 phba->SerialNumber[i] =
286 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
287 i++;
288 j = (status & 0xf);
289 if (j <= 9)
290 phba->SerialNumber[i] =
291 (char)((uint8_t) 0x30 + (uint8_t) j);
292 else
293 phba->SerialNumber[i] =
294 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
295 }
296 }
297
dea31012005-04-17 16:05:31 -0500298 lpfc_read_config(phba, pmb);
299 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
300 lpfc_printf_log(phba,
301 KERN_ERR,
302 LOG_INIT,
303 "%d:0453 Adapter failed to init, mbxCmd x%x "
304 "READ_CONFIG, mbxStatus x%x\n",
305 phba->brd_no,
306 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500307 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500308 mempool_free( pmb, phba->mbox_mem_pool);
309 return -EIO;
310 }
311
312 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
313 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
314 phba->cfg_hba_queue_depth =
315 mb->un.varRdConfig.max_xri + 1;
316
317 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500318
319 /* Get the default values for Model Name and Description */
320 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
321
322 if ((phba->cfg_link_speed > LINK_SPEED_10G)
323 || ((phba->cfg_link_speed == LINK_SPEED_1G)
324 && !(phba->lmt & LMT_1Gb))
325 || ((phba->cfg_link_speed == LINK_SPEED_2G)
326 && !(phba->lmt & LMT_2Gb))
327 || ((phba->cfg_link_speed == LINK_SPEED_4G)
328 && !(phba->lmt & LMT_4Gb))
329 || ((phba->cfg_link_speed == LINK_SPEED_8G)
330 && !(phba->lmt & LMT_8Gb))
331 || ((phba->cfg_link_speed == LINK_SPEED_10G)
332 && !(phba->lmt & LMT_10Gb))) {
333 /* Reset link speed to auto */
dea31012005-04-17 16:05:31 -0500334 lpfc_printf_log(phba,
335 KERN_WARNING,
336 LOG_LINK_EVENT,
337 "%d:1302 Invalid speed for this board: "
338 "Reset link speed to auto: x%x\n",
339 phba->brd_no,
340 phba->cfg_link_speed);
341 phba->cfg_link_speed = LINK_SPEED_AUTO;
342 }
343
James Smart2e0fef82007-06-17 19:56:36 -0500344 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500345
346 /* Only process IOCBs on ring 0 till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500347 if (psli->ring[psli->extra_ring].cmdringaddr)
348 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500349 if (psli->ring[psli->fcp_ring].cmdringaddr)
350 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
351 if (psli->ring[psli->next_ring].cmdringaddr)
352 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
353
354 /* Post receive buffers for desired rings */
355 lpfc_post_rcv_buf(phba);
356
357 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500358 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500359 status = readl(phba->HCregaddr);
360 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
361 if (psli->num_rings > 0)
362 status |= HC_R0INT_ENA;
363 if (psli->num_rings > 1)
364 status |= HC_R1INT_ENA;
365 if (psli->num_rings > 2)
366 status |= HC_R2INT_ENA;
367 if (psli->num_rings > 3)
368 status |= HC_R3INT_ENA;
369
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500370 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
371 (phba->cfg_poll & DISABLE_FCP_RING_INT))
372 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
373
dea31012005-04-17 16:05:31 -0500374 writel(status, phba->HCregaddr);
375 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500376 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500377
378 /*
379 * Setup the ring 0 (els) timeout handler
380 */
381 timeout = phba->fc_ratov << 1;
James Smart2e0fef82007-06-17 19:56:36 -0500382 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -0500383
384 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
385 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart8aee9182006-08-31 12:27:57 -0400386 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -0400387 lpfc_set_loopback_flag(phba);
James Smart8aee9182006-08-31 12:27:57 -0400388 if (rc != MBX_SUCCESS) {
dea31012005-04-17 16:05:31 -0500389 lpfc_printf_log(phba,
390 KERN_ERR,
391 LOG_INIT,
392 "%d:0454 Adapter failed to init, mbxCmd x%x "
393 "INIT_LINK, mbxStatus x%x\n",
394 phba->brd_no,
395 mb->mbxCommand, mb->mbxStatus);
396
397 /* Clear all interrupt enable conditions */
398 writel(0, phba->HCregaddr);
399 readl(phba->HCregaddr); /* flush */
400 /* Clear all pending interrupts */
401 writel(0xffffffff, phba->HAregaddr);
402 readl(phba->HAregaddr); /* flush */
403
James Smart2e0fef82007-06-17 19:56:36 -0500404 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400405 if (rc != MBX_BUSY)
406 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500407 return -EIO;
408 }
409 /* MBOX buffer will be freed in mbox compl */
410
James Smartce8b3ce2006-07-06 15:50:36 -0400411 return (0);
412}
413
dea31012005-04-17 16:05:31 -0500414/************************************************************************/
415/* */
416/* lpfc_hba_down_prep */
417/* This routine will do LPFC uninitialization before the */
418/* HBA is reset when bringing down the SLI Layer. This will be */
419/* initialized as a SLI layer callback routine. */
420/* This routine returns 0 on success. Any other return value */
421/* indicates an error. */
422/* */
423/************************************************************************/
424int
James Smart2e0fef82007-06-17 19:56:36 -0500425lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500426{
James Smart2e0fef82007-06-17 19:56:36 -0500427 struct lpfc_vport *vport = phba->pport;
428
dea31012005-04-17 16:05:31 -0500429 /* Disable interrupts */
430 writel(0, phba->HCregaddr);
431 readl(phba->HCregaddr); /* flush */
432
James Smart2e0fef82007-06-17 19:56:36 -0500433 /* Cleanup potential discovery resources */
434 lpfc_els_flush_rscn(vport);
435 lpfc_els_flush_cmd(vport);
436 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -0500437
James Smart2e0fef82007-06-17 19:56:36 -0500438 return 0;
dea31012005-04-17 16:05:31 -0500439}
440
441/************************************************************************/
442/* */
Jamie Wellnitz41415862006-02-28 19:25:27 -0500443/* lpfc_hba_down_post */
444/* This routine will do uninitialization after the HBA is reset */
445/* when bringing down the SLI Layer. */
446/* This routine returns 0 on success. Any other return value */
447/* indicates an error. */
448/* */
449/************************************************************************/
450int
James Smart2e0fef82007-06-17 19:56:36 -0500451lpfc_hba_down_post(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500452{
453 struct lpfc_sli *psli = &phba->sli;
454 struct lpfc_sli_ring *pring;
455 struct lpfc_dmabuf *mp, *next_mp;
456 int i;
457
458 /* Cleanup preposted buffers on the ELS ring */
459 pring = &psli->ring[LPFC_ELS_RING];
460 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
461 list_del(&mp->list);
462 pring->postbufq_cnt--;
463 lpfc_mbuf_free(phba, mp->virt, mp->phys);
464 kfree(mp);
465 }
466
467 for (i = 0; i < psli->num_rings; i++) {
468 pring = &psli->ring[i];
469 lpfc_sli_abort_iocb_ring(phba, pring);
470 }
471
472 return 0;
473}
474
475/************************************************************************/
476/* */
dea31012005-04-17 16:05:31 -0500477/* lpfc_handle_eratt */
478/* This routine will handle processing a Host Attention */
479/* Error Status event. This will be initialized */
480/* as a SLI layer callback routine. */
481/* */
482/************************************************************************/
483void
James Smart2e0fef82007-06-17 19:56:36 -0500484lpfc_handle_eratt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500485{
James Smart2e0fef82007-06-17 19:56:36 -0500486 struct lpfc_vport *vport = phba->pport;
487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
488 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500489 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400490 uint32_t event_data;
James Smart2e0fef82007-06-17 19:56:36 -0500491
Linas Vepstas8d63f372007-02-14 14:28:36 -0600492 /* If the pci channel is offline, ignore possible errors,
493 * since we cannot communicate with the pci card anyway. */
494 if (pci_channel_offline(phba->pcidev))
495 return;
dea31012005-04-17 16:05:31 -0500496
James Smartf5603512006-12-02 13:35:43 -0500497 if (phba->work_hs & HS_FFER6 ||
498 phba->work_hs & HS_FFER5) {
dea31012005-04-17 16:05:31 -0500499 /* Re-establishing Link */
500 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
501 "%d:1301 Re-establishing Link "
502 "Data: x%x x%x x%x\n",
503 phba->brd_no, phba->work_hs,
504 phba->work_status[0], phba->work_status[1]);
James Smart2e0fef82007-06-17 19:56:36 -0500505 spin_lock_irq(shost->host_lock);
506 vport->fc_flag |= FC_ESTABLISH_LINK;
James Smart92908312006-03-07 15:04:13 -0500507 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -0500508 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500509
510 /*
511 * Firmware stops when it triggled erratt with HS_FFER6.
512 * That could cause the I/Os dropped by the firmware.
513 * Error iocb (I/O) on txcmplq and let the SCSI layer
514 * retry it after re-establishing link.
515 */
516 pring = &psli->ring[psli->fcp_ring];
517 lpfc_sli_abort_iocb_ring(phba, pring);
518
519
520 /*
521 * There was a firmware error. Take the hba offline and then
522 * attempt to restart it.
523 */
James Smart46fa3112007-04-25 09:51:45 -0400524 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500525 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500526 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -0500527 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
528 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
James Smart46fa3112007-04-25 09:51:45 -0400529 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500530 return;
531 }
James Smart46fa3112007-04-25 09:51:45 -0400532 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500533 } else {
534 /* The if clause above forces this code path when the status
535 * failure is a value other than FFER6. Do not call the offline
536 * twice. This is the adapter hardware error path.
537 */
538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
539 "%d:0457 Adapter Hardware Error "
540 "Data: x%x x%x x%x\n",
541 phba->brd_no, phba->work_hs,
542 phba->work_status[0], phba->work_status[1]);
543
James Smartd2873e42006-08-18 17:46:43 -0400544 event_data = FC_REG_DUMP_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -0500545 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -0400546 sizeof(event_data), (char *) &event_data,
547 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
548
James Smart92908312006-03-07 15:04:13 -0500549 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart46fa3112007-04-25 09:51:45 -0400550 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -0500551 lpfc_offline(phba);
James Smart46fa3112007-04-25 09:51:45 -0400552 lpfc_unblock_mgmt_io(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500553 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500554 lpfc_hba_down_post(phba);
dea31012005-04-17 16:05:31 -0500555 }
556}
557
558/************************************************************************/
559/* */
560/* lpfc_handle_latt */
561/* This routine will handle processing a Host Attention */
562/* Link Status event. This will be initialized */
563/* as a SLI layer callback routine. */
564/* */
565/************************************************************************/
566void
James Smart2e0fef82007-06-17 19:56:36 -0500567lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500568{
James Smart2e0fef82007-06-17 19:56:36 -0500569 struct lpfc_vport *vport = phba->pport;
570 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500571 LPFC_MBOXQ_t *pmb;
572 volatile uint32_t control;
573 struct lpfc_dmabuf *mp;
574 int rc = -ENOMEM;
575
576 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
577 if (!pmb)
578 goto lpfc_handle_latt_err_exit;
579
580 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
581 if (!mp)
582 goto lpfc_handle_latt_free_pmb;
583
584 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
585 if (!mp->virt)
586 goto lpfc_handle_latt_free_mp;
587
588 rc = -EIO;
589
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500590 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -0500591 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -0500592
593 psli->slistat.link_event++;
594 lpfc_read_la(phba, pmb, mp);
595 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -0500596 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500597 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
598 if (rc == MBX_NOT_FINISHED)
James Smart14691152006-12-02 13:34:28 -0500599 goto lpfc_handle_latt_free_mbuf;
dea31012005-04-17 16:05:31 -0500600
601 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -0500602 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500603 writel(HA_LATT, phba->HAregaddr);
604 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500605 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500606
607 return;
608
James Smart14691152006-12-02 13:34:28 -0500609lpfc_handle_latt_free_mbuf:
610 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -0500611lpfc_handle_latt_free_mp:
612 kfree(mp);
613lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -0400614 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500615lpfc_handle_latt_err_exit:
616 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500618 psli->sli_flag |= LPFC_PROCESS_LA;
619 control = readl(phba->HCregaddr);
620 control |= HC_LAINT_ENA;
621 writel(control, phba->HCregaddr);
622 readl(phba->HCregaddr); /* flush */
623
624 /* Clear Link Attention in HA REG */
625 writel(HA_LATT, phba->HAregaddr);
626 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500627 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500628 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500629 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500630
631 /* The other case is an error from issue_mbox */
632 if (rc == -ENOMEM)
633 lpfc_printf_log(phba,
634 KERN_WARNING,
635 LOG_MBOX,
636 "%d:0300 READ_LA: no buffers\n",
637 phba->brd_no);
638
639 return;
640}
641
642/************************************************************************/
643/* */
644/* lpfc_parse_vpd */
645/* This routine will parse the VPD data */
646/* */
647/************************************************************************/
648static int
James Smart2e0fef82007-06-17 19:56:36 -0500649lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -0500650{
651 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -0500652 int Length;
dea31012005-04-17 16:05:31 -0500653 int i, j;
654 int finished = 0;
655 int index = 0;
656
657 if (!vpd)
658 return 0;
659
660 /* Vital Product */
661 lpfc_printf_log(phba,
662 KERN_INFO,
663 LOG_INIT,
664 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
665 phba->brd_no,
666 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
667 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500668 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -0500669 switch (vpd[index]) {
670 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500671 case 0x91:
dea31012005-04-17 16:05:31 -0500672 index += 1;
673 lenlo = vpd[index];
674 index += 1;
675 lenhi = vpd[index];
676 index += 1;
677 i = ((((unsigned short)lenhi) << 8) + lenlo);
678 index += i;
679 break;
680 case 0x90:
681 index += 1;
682 lenlo = vpd[index];
683 index += 1;
684 lenhi = vpd[index];
685 index += 1;
686 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500687 if (Length > len - index)
688 Length = len - index;
dea31012005-04-17 16:05:31 -0500689 while (Length > 0) {
690 /* Look for Serial Number */
691 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
692 index += 2;
693 i = vpd[index];
694 index += 1;
695 j = 0;
696 Length -= (3+i);
697 while(i--) {
698 phba->SerialNumber[j++] = vpd[index++];
699 if (j == 31)
700 break;
701 }
702 phba->SerialNumber[j] = 0;
703 continue;
704 }
705 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
706 phba->vpd_flag |= VPD_MODEL_DESC;
707 index += 2;
708 i = vpd[index];
709 index += 1;
710 j = 0;
711 Length -= (3+i);
712 while(i--) {
713 phba->ModelDesc[j++] = vpd[index++];
714 if (j == 255)
715 break;
716 }
717 phba->ModelDesc[j] = 0;
718 continue;
719 }
720 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
721 phba->vpd_flag |= VPD_MODEL_NAME;
722 index += 2;
723 i = vpd[index];
724 index += 1;
725 j = 0;
726 Length -= (3+i);
727 while(i--) {
728 phba->ModelName[j++] = vpd[index++];
729 if (j == 79)
730 break;
731 }
732 phba->ModelName[j] = 0;
733 continue;
734 }
735 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
736 phba->vpd_flag |= VPD_PROGRAM_TYPE;
737 index += 2;
738 i = vpd[index];
739 index += 1;
740 j = 0;
741 Length -= (3+i);
742 while(i--) {
743 phba->ProgramType[j++] = vpd[index++];
744 if (j == 255)
745 break;
746 }
747 phba->ProgramType[j] = 0;
748 continue;
749 }
750 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
751 phba->vpd_flag |= VPD_PORT;
752 index += 2;
753 i = vpd[index];
754 index += 1;
755 j = 0;
756 Length -= (3+i);
757 while(i--) {
758 phba->Port[j++] = vpd[index++];
759 if (j == 19)
760 break;
761 }
762 phba->Port[j] = 0;
763 continue;
764 }
765 else {
766 index += 2;
767 i = vpd[index];
768 index += 1;
769 index += i;
770 Length -= (3 + i);
771 }
772 }
773 finished = 0;
774 break;
775 case 0x78:
776 finished = 1;
777 break;
778 default:
779 index ++;
780 break;
781 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500782 }
dea31012005-04-17 16:05:31 -0500783
784 return(1);
785}
786
787static void
James Smart2e0fef82007-06-17 19:56:36 -0500788lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -0500789{
790 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -0500791 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500792 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500793 struct {
794 char * name;
795 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500796 char * bus;
James Smart18a3b592006-12-02 13:35:08 -0500797 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500798
799 if (mdp && mdp[0] != '\0'
800 && descp && descp[0] != '\0')
801 return;
802
803 if (phba->lmt & LMT_10Gb)
804 max_speed = 10;
805 else if (phba->lmt & LMT_8Gb)
806 max_speed = 8;
807 else if (phba->lmt & LMT_4Gb)
808 max_speed = 4;
809 else if (phba->lmt & LMT_2Gb)
810 max_speed = 2;
811 else
812 max_speed = 1;
dea31012005-04-17 16:05:31 -0500813
814 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -0500815
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500816 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400817 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -0500818 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400819 break;
dea31012005-04-17 16:05:31 -0500820 case PCI_DEVICE_ID_SUPERFLY:
821 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -0500822 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500823 else
James Smart18a3b592006-12-02 13:35:08 -0500824 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500825 break;
826 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -0500827 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500828 break;
829 case PCI_DEVICE_ID_CENTAUR:
830 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -0500831 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500832 else
James Smart18a3b592006-12-02 13:35:08 -0500833 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500834 break;
835 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -0500836 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -0500837 break;
838 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -0500839 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500840 break;
841 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -0500842 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500843 break;
844 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -0500845 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500846 break;
847 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -0500848 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500849 break;
850 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -0500851 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500852 break;
853 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -0500854 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -0500855 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500856 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500857 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500858 break;
859 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -0500860 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500861 break;
862 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -0500863 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500864 break;
865 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500866 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500867 break;
868 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -0500869 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500870 break;
dea31012005-04-17 16:05:31 -0500871 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -0500872 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -0500873 break;
874 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -0500875 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -0500876 break;
877 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -0500878 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -0500879 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500880 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -0500881 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500882 break;
883 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smart18a3b592006-12-02 13:35:08 -0500884 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500885 break;
dea31012005-04-17 16:05:31 -0500886 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -0500887 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -0500888 break;
889 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -0500890 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -0500891 break;
892 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -0500893 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -0500894 break;
895 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -0500896 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -0400897 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500898 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -0500899 m = (typeof(m)){"LP11000-S", max_speed,
900 "PCI-X2"};
901 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500902 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -0500903 m = (typeof(m)){"LPe11000-S", max_speed,
904 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -0500905 break;
James Smartb87eab32007-04-25 09:53:28 -0400906 case PCI_DEVICE_ID_SAT:
907 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
908 break;
909 case PCI_DEVICE_ID_SAT_MID:
910 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
911 break;
912 case PCI_DEVICE_ID_SAT_SMB:
913 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
914 break;
915 case PCI_DEVICE_ID_SAT_DCSP:
916 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
917 break;
918 case PCI_DEVICE_ID_SAT_SCSP:
919 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
920 break;
921 case PCI_DEVICE_ID_SAT_S:
922 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
923 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -0500924 default:
Randy Dunlap041976f2006-06-25 01:58:51 -0700925 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -0500926 break;
dea31012005-04-17 16:05:31 -0500927 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500928
929 if (mdp && mdp[0] == '\0')
930 snprintf(mdp, 79,"%s", m.name);
931 if (descp && descp[0] == '\0')
932 snprintf(descp, 255,
James Smart18a3b592006-12-02 13:35:08 -0500933 "Emulex %s %dGb %s Fibre Channel Adapter",
934 m.name, m.max_speed, m.bus);
dea31012005-04-17 16:05:31 -0500935}
936
937/**************************************************/
938/* lpfc_post_buffer */
939/* */
940/* This routine will post count buffers to the */
941/* ring with the QUE_RING_BUF_CN command. This */
942/* allows 3 buffers / command to be posted. */
943/* Returns the number of buffers NOT posted. */
944/**************************************************/
945int
James Smart2e0fef82007-06-17 19:56:36 -0500946lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
dea31012005-04-17 16:05:31 -0500947 int type)
948{
949 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400950 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -0500951 struct lpfc_dmabuf *mp1, *mp2;
952
953 cnt += pring->missbufcnt;
954
955 /* While there are buffers to post */
956 while (cnt > 0) {
957 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400958 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500959 if (iocb == NULL) {
960 pring->missbufcnt = cnt;
961 return cnt;
962 }
dea31012005-04-17 16:05:31 -0500963 icmd = &iocb->iocb;
964
965 /* 2 buffers can be posted per command */
966 /* Allocate buffer to post */
967 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
968 if (mp1)
969 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
970 &mp1->phys);
971 if (mp1 == 0 || mp1->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800972 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -0500973 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500974 pring->missbufcnt = cnt;
975 return cnt;
976 }
977
978 INIT_LIST_HEAD(&mp1->list);
979 /* Allocate buffer to post */
980 if (cnt > 1) {
981 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
982 if (mp2)
983 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
984 &mp2->phys);
985 if (mp2 == 0 || mp2->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800986 kfree(mp2);
dea31012005-04-17 16:05:31 -0500987 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
988 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -0500989 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500990 pring->missbufcnt = cnt;
991 return cnt;
992 }
993
994 INIT_LIST_HEAD(&mp2->list);
995 } else {
996 mp2 = NULL;
997 }
998
999 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1000 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1001 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1002 icmd->ulpBdeCount = 1;
1003 cnt--;
1004 if (mp2) {
1005 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1006 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1007 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1008 cnt--;
1009 icmd->ulpBdeCount = 2;
1010 }
1011
1012 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1013 icmd->ulpLe = 1;
1014
dea31012005-04-17 16:05:31 -05001015 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1016 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1017 kfree(mp1);
1018 cnt++;
1019 if (mp2) {
1020 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1021 kfree(mp2);
1022 cnt++;
1023 }
James Bottomley604a3e32005-10-29 10:28:33 -05001024 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001025 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001026 return cnt;
1027 }
dea31012005-04-17 16:05:31 -05001028 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1029 if (mp2) {
1030 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1031 }
1032 }
1033 pring->missbufcnt = 0;
1034 return 0;
1035}
1036
1037/************************************************************************/
1038/* */
1039/* lpfc_post_rcv_buf */
1040/* This routine post initial rcv buffers to the configured rings */
1041/* */
1042/************************************************************************/
1043static int
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001045{
1046 struct lpfc_sli *psli = &phba->sli;
1047
1048 /* Ring 0, ELS / CT buffers */
1049 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
1050 /* Ring 2 - FCP no buffers needed */
1051
1052 return 0;
1053}
1054
1055#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1056
1057/************************************************************************/
1058/* */
1059/* lpfc_sha_init */
1060/* */
1061/************************************************************************/
1062static void
1063lpfc_sha_init(uint32_t * HashResultPointer)
1064{
1065 HashResultPointer[0] = 0x67452301;
1066 HashResultPointer[1] = 0xEFCDAB89;
1067 HashResultPointer[2] = 0x98BADCFE;
1068 HashResultPointer[3] = 0x10325476;
1069 HashResultPointer[4] = 0xC3D2E1F0;
1070}
1071
1072/************************************************************************/
1073/* */
1074/* lpfc_sha_iterate */
1075/* */
1076/************************************************************************/
1077static void
1078lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1079{
1080 int t;
1081 uint32_t TEMP;
1082 uint32_t A, B, C, D, E;
1083 t = 16;
1084 do {
1085 HashWorkingPointer[t] =
1086 S(1,
1087 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1088 8] ^
1089 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1090 } while (++t <= 79);
1091 t = 0;
1092 A = HashResultPointer[0];
1093 B = HashResultPointer[1];
1094 C = HashResultPointer[2];
1095 D = HashResultPointer[3];
1096 E = HashResultPointer[4];
1097
1098 do {
1099 if (t < 20) {
1100 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1101 } else if (t < 40) {
1102 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1103 } else if (t < 60) {
1104 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1105 } else {
1106 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1107 }
1108 TEMP += S(5, A) + E + HashWorkingPointer[t];
1109 E = D;
1110 D = C;
1111 C = S(30, B);
1112 B = A;
1113 A = TEMP;
1114 } while (++t <= 79);
1115
1116 HashResultPointer[0] += A;
1117 HashResultPointer[1] += B;
1118 HashResultPointer[2] += C;
1119 HashResultPointer[3] += D;
1120 HashResultPointer[4] += E;
1121
1122}
1123
1124/************************************************************************/
1125/* */
1126/* lpfc_challenge_key */
1127/* */
1128/************************************************************************/
1129static void
1130lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1131{
1132 *HashWorking = (*RandomChallenge ^ *HashWorking);
1133}
1134
1135/************************************************************************/
1136/* */
1137/* lpfc_hba_init */
1138/* */
1139/************************************************************************/
1140void
1141lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1142{
1143 int t;
1144 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001145 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001146
1147 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1148 if (!HashWorking)
1149 return;
1150
1151 memset(HashWorking, 0, (80 * sizeof(uint32_t)));
1152 HashWorking[0] = HashWorking[78] = *pwwnn++;
1153 HashWorking[1] = HashWorking[79] = *pwwnn;
1154
1155 for (t = 0; t < 7; t++)
1156 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1157
1158 lpfc_sha_init(hbainit);
1159 lpfc_sha_iterate(hbainit, HashWorking);
1160 kfree(HashWorking);
1161}
1162
1163static void
James Smart2e0fef82007-06-17 19:56:36 -05001164lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001165{
1166 struct lpfc_nodelist *ndlp, *next_ndlp;
1167
1168 /* clean up phba - lpfc specific */
James Smart2e0fef82007-06-17 19:56:36 -05001169 lpfc_can_disctmo(vport);
1170 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart329f9bc2007-04-25 09:53:01 -04001171 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001172
James Smart2e0fef82007-06-17 19:56:36 -05001173 INIT_LIST_HEAD(&vport->fc_nodes);
dea31012005-04-17 16:05:31 -05001174
dea31012005-04-17 16:05:31 -05001175 return;
1176}
1177
1178static void
1179lpfc_establish_link_tmo(unsigned long ptr)
1180{
James Smart2e0fef82007-06-17 19:56:36 -05001181 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1182 struct lpfc_vport *vport = phba->pport;
1183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001184 unsigned long iflag;
1185
1186
1187 /* Re-establishing Link, timer expired */
1188 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1189 "%d:1300 Re-establishing Link, timer expired "
1190 "Data: x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001191 phba->brd_no, vport->fc_flag,
1192 vport->port_state);
1193 spin_lock_irqsave(shost->host_lock, iflag);
1194 vport->fc_flag &= ~FC_ESTABLISH_LINK;
1195 spin_unlock_irqrestore(shost->host_lock, iflag);
dea31012005-04-17 16:05:31 -05001196}
1197
James Smart2e0fef82007-06-17 19:56:36 -05001198static void
1199lpfc_stop_timer(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001200{
James Smart2e0fef82007-06-17 19:56:36 -05001201 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -05001202
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001203 del_timer_sync(&phba->fcp_poll_timer);
dea31012005-04-17 16:05:31 -05001204 del_timer_sync(&phba->fc_estabtmo);
James Smart2e0fef82007-06-17 19:56:36 -05001205 del_timer_sync(&vport->els_tmofunc);
1206 del_timer_sync(&vport->fc_fdmitmo);
1207 del_timer_sync(&vport->fc_disctmo);
1208 del_timer_sync(&phba->sli.mbox_tmo);
1209 return;
dea31012005-04-17 16:05:31 -05001210}
1211
1212int
James Smart2e0fef82007-06-17 19:56:36 -05001213lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001214{
James Smart2e0fef82007-06-17 19:56:36 -05001215 struct lpfc_vport *vport = phba->pport;
1216 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1217
dea31012005-04-17 16:05:31 -05001218 if (!phba)
1219 return 0;
1220
James Smart2e0fef82007-06-17 19:56:36 -05001221 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001222 return 0;
1223
1224 lpfc_printf_log(phba,
1225 KERN_WARNING,
1226 LOG_INIT,
1227 "%d:0458 Bring Adapter online\n",
1228 phba->brd_no);
1229
James Smart46fa3112007-04-25 09:51:45 -04001230 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001231
James Smart46fa3112007-04-25 09:51:45 -04001232 if (!lpfc_sli_queue_setup(phba)) {
1233 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001234 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001235 }
1236
1237 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1238 lpfc_unblock_mgmt_io(phba);
1239 return 1;
1240 }
dea31012005-04-17 16:05:31 -05001241
James Smart2e0fef82007-06-17 19:56:36 -05001242 spin_lock_irq(shost->host_lock);
1243 vport->fc_flag &= ~FC_OFFLINE_MODE;
1244 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001245
James Smart46fa3112007-04-25 09:51:45 -04001246 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001247 return 0;
1248}
1249
James Smart46fa3112007-04-25 09:51:45 -04001250void
1251lpfc_block_mgmt_io(struct lpfc_hba * phba)
dea31012005-04-17 16:05:31 -05001252{
dea31012005-04-17 16:05:31 -05001253 unsigned long iflag;
dea31012005-04-17 16:05:31 -05001254
James Smart2e0fef82007-06-17 19:56:36 -05001255 spin_lock_irqsave(&phba->hbalock, iflag);
1256 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1257 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001258}
1259
1260void
1261lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1262{
1263 unsigned long iflag;
1264
James Smart2e0fef82007-06-17 19:56:36 -05001265 spin_lock_irqsave(&phba->hbalock, iflag);
1266 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1267 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001268}
1269
1270void
1271lpfc_offline_prep(struct lpfc_hba * phba)
1272{
James Smart2e0fef82007-06-17 19:56:36 -05001273 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001274 struct lpfc_nodelist *ndlp, *next_ndlp;
dea31012005-04-17 16:05:31 -05001275
James Smart2e0fef82007-06-17 19:56:36 -05001276 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001277 return;
dea31012005-04-17 16:05:31 -05001278
James Smart46fa3112007-04-25 09:51:45 -04001279 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001280
1281 lpfc_linkdown(phba);
1282
James Smart46fa3112007-04-25 09:51:45 -04001283 /* Issue an unreg_login to all nodes */
James Smart2e0fef82007-06-17 19:56:36 -05001284 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart685f0bf2007-04-25 09:53:08 -04001285 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001286 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001287
James Smart46fa3112007-04-25 09:51:45 -04001288 lpfc_sli_flush_mbox_queue(phba);
1289}
1290
1291void
James Smart2e0fef82007-06-17 19:56:36 -05001292lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04001293{
James Smart2e0fef82007-06-17 19:56:36 -05001294 struct lpfc_vport *vport = phba->pport;
1295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart46fa3112007-04-25 09:51:45 -04001296 unsigned long iflag;
1297
James Smart2e0fef82007-06-17 19:56:36 -05001298 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001299 return;
James Smart688a8862006-07-06 15:49:56 -04001300
dea31012005-04-17 16:05:31 -05001301 /* stop all timers associated with this hba */
1302 lpfc_stop_timer(phba);
dea31012005-04-17 16:05:31 -05001303
1304 lpfc_printf_log(phba,
1305 KERN_WARNING,
1306 LOG_INIT,
1307 "%d:0460 Bring Adapter offline\n",
1308 phba->brd_no);
1309
1310 /* Bring down the SLI Layer and cleanup. The HBA is offline
1311 now. */
1312 lpfc_sli_hba_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001313 lpfc_cleanup(vport);
1314 spin_lock_irqsave(shost->host_lock, iflag);
1315 spin_lock(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04001316 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001317 vport->work_port_events = 0;
1318 vport->fc_flag |= FC_OFFLINE_MODE;
1319 spin_unlock(&phba->hbalock);
1320 spin_unlock_irqrestore(shost->host_lock, iflag);
dea31012005-04-17 16:05:31 -05001321}
1322
1323/******************************************************************************
1324* Function name: lpfc_scsi_free
1325*
1326* Description: Called from lpfc_pci_remove_one free internal driver resources
1327*
1328******************************************************************************/
1329static int
James Smart2e0fef82007-06-17 19:56:36 -05001330lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001331{
1332 struct lpfc_scsi_buf *sb, *sb_next;
1333 struct lpfc_iocbq *io, *io_next;
1334
James Smart2e0fef82007-06-17 19:56:36 -05001335 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001336 /* Release all the lpfc_scsi_bufs maintained by this host. */
1337 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1338 list_del(&sb->list);
1339 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1340 sb->dma_handle);
1341 kfree(sb);
1342 phba->total_scsi_bufs--;
1343 }
1344
1345 /* Release all the lpfc_iocbq entries maintained by this host. */
1346 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1347 list_del(&io->list);
1348 kfree(io);
1349 phba->total_iocbq_bufs--;
1350 }
1351
James Smart2e0fef82007-06-17 19:56:36 -05001352 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001353
1354 return 0;
1355}
1356
James Smart2e0fef82007-06-17 19:56:36 -05001357struct lpfc_vport *
1358lpfc_create_port(struct lpfc_hba *phba, int instance)
James Smart47a86172007-04-25 09:53:22 -04001359{
James Smart2e0fef82007-06-17 19:56:36 -05001360 struct lpfc_vport *vport;
1361 struct Scsi_Host *shost;
1362 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04001363
James Smart2e0fef82007-06-17 19:56:36 -05001364 shost = scsi_host_alloc(&lpfc_template, sizeof(struct lpfc_vport));
1365 if (!shost)
1366 goto out;
James Smart47a86172007-04-25 09:53:22 -04001367
James Smart2e0fef82007-06-17 19:56:36 -05001368 vport = (struct lpfc_vport *) shost->hostdata;
1369 vport->phba = phba;
James Smart47a86172007-04-25 09:53:22 -04001370
James Smart2e0fef82007-06-17 19:56:36 -05001371 vport->load_flag |= FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001372
James Smart2e0fef82007-06-17 19:56:36 -05001373 shost->unique_id = instance;
1374 shost->max_id = LPFC_MAX_TARGET;
1375 shost->max_lun = phba->cfg_max_luns;
1376 shost->this_id = -1;
1377 shost->max_cmd_len = 16;
James Smart47a86172007-04-25 09:53:22 -04001378 /*
James Smart2e0fef82007-06-17 19:56:36 -05001379 * Set initial can_queue value since 0 is no longer supported and
1380 * scsi_add_host will fail. This will be adjusted later based on the
1381 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04001382 */
James Smart2e0fef82007-06-17 19:56:36 -05001383 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1384 shost->transportt = lpfc_transport_template;
James Smart47a86172007-04-25 09:53:22 -04001385
James Smart2e0fef82007-06-17 19:56:36 -05001386 /* Initialize all internally managed lists. */
1387 INIT_LIST_HEAD(&vport->fc_nodes);
1388 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04001389
James Smart2e0fef82007-06-17 19:56:36 -05001390 init_timer(&vport->fc_disctmo);
1391 vport->fc_disctmo.function = lpfc_disc_timeout;
1392 vport->fc_disctmo.data = (unsigned long) vport;
James Smart47a86172007-04-25 09:53:22 -04001393
James Smart2e0fef82007-06-17 19:56:36 -05001394 init_timer(&vport->fc_fdmitmo);
1395 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1396 vport->fc_fdmitmo.data = (unsigned long) vport;
James Smart47a86172007-04-25 09:53:22 -04001397
James Smart2e0fef82007-06-17 19:56:36 -05001398 init_timer(&vport->els_tmofunc);
1399 vport->els_tmofunc.function = lpfc_els_timeout;
1400 vport->els_tmofunc.data = (unsigned long) vport;
James Smart47a86172007-04-25 09:53:22 -04001401
James Smart2e0fef82007-06-17 19:56:36 -05001402 error = scsi_add_host(shost, &phba->pcidev->dev);
1403 if (error)
1404 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04001405
James Smart2e0fef82007-06-17 19:56:36 -05001406 list_add_tail(&vport->listentry, &phba->port_list);
1407 scsi_scan_host(shost);
1408 return vport;
James Smart47a86172007-04-25 09:53:22 -04001409
James Smart2e0fef82007-06-17 19:56:36 -05001410out_put_shost:
1411 scsi_host_put(shost);
1412out:
1413 return NULL;
James Smart47a86172007-04-25 09:53:22 -04001414}
1415
James Smart2e0fef82007-06-17 19:56:36 -05001416void
1417destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04001418{
James Smart2e0fef82007-06-17 19:56:36 -05001419 lpfc_cleanup(vport);
1420 list_del(&vport->listentry);
1421 lpfc_free_sysfs_attr(vport);
1422 fc_remove_host(lpfc_shost_from_vport(vport));
1423 scsi_remove_host(lpfc_shost_from_vport(vport));
1424 return;
1425}
James Smart47a86172007-04-25 09:53:22 -04001426
James Smart2e0fef82007-06-17 19:56:36 -05001427static void
1428lpfc_remove_device(struct lpfc_vport *vport)
1429{
1430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1431 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001432
James Smart2e0fef82007-06-17 19:56:36 -05001433 lpfc_free_sysfs_attr(vport);
James Smart47a86172007-04-25 09:53:22 -04001434
James Smart2e0fef82007-06-17 19:56:36 -05001435 spin_lock_irq(shost->host_lock);
1436 vport->fc_flag |= FC_UNLOADING;
1437 spin_unlock_irq(shost->host_lock);
1438
1439 fc_remove_host(shost);
1440 scsi_remove_host(shost);
1441
1442 kthread_stop(phba->worker_thread);
1443}
1444
1445void lpfc_scan_start(struct Scsi_Host *shost)
1446{
1447 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1448 struct lpfc_hba *phba = vport->phba;
1449
1450 if (lpfc_alloc_sysfs_attr(vport))
James Smart47a86172007-04-25 09:53:22 -04001451 goto error;
1452
1453 /*
1454 * hba setup may have changed the hba_queue_depth so we need to adjust
1455 * the value of can_queue.
1456 */
James Smart2e0fef82007-06-17 19:56:36 -05001457 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart47a86172007-04-25 09:53:22 -04001458 return;
1459
1460error:
James Smart2e0fef82007-06-17 19:56:36 -05001461 lpfc_remove_device(vport);
James Smart47a86172007-04-25 09:53:22 -04001462}
1463
1464int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1465{
James Smart2e0fef82007-06-17 19:56:36 -05001466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1467 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04001468
James Smart2e0fef82007-06-17 19:56:36 -05001469 if (time >= 30 * HZ) {
1470 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1471 "%d:0461 Scanning longer than 30 "
1472 "seconds. Continuing initialization\n",
1473 phba->brd_no);
James Smart47a86172007-04-25 09:53:22 -04001474 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05001475 }
1476 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1477 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1478 "%d:0465 Link down longer than 15 "
1479 "seconds. Continuing initialization\n",
1480 phba->brd_no);
1481 goto finished;
1482 }
James Smart47a86172007-04-25 09:53:22 -04001483
James Smart2e0fef82007-06-17 19:56:36 -05001484 if (vport->port_state != LPFC_VPORT_READY)
James Smart47a86172007-04-25 09:53:22 -04001485 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001486 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart47a86172007-04-25 09:53:22 -04001487 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001488 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart47a86172007-04-25 09:53:22 -04001489 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001490 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart47a86172007-04-25 09:53:22 -04001491 return 0;
1492
1493finished:
James Smart47a86172007-04-25 09:53:22 -04001494 /*
James Smart2e0fef82007-06-17 19:56:36 -05001495 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04001496 */
1497
James Smart2e0fef82007-06-17 19:56:36 -05001498 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1499 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04001500 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1501
1502 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001503 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001504 fc_host_supported_fc4s(shost)[2] = 1;
1505 fc_host_supported_fc4s(shost)[7] = 1;
1506
1507 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1508
1509 fc_host_supported_speeds(shost) = 0;
1510 if (phba->lmt & LMT_10Gb)
1511 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1512 if (phba->lmt & LMT_4Gb)
1513 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1514 if (phba->lmt & LMT_2Gb)
1515 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1516 if (phba->lmt & LMT_1Gb)
1517 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1518
1519 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05001520 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1521 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04001522
1523 /* This value is also unchanging */
1524 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05001525 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04001526 fc_host_active_fc4s(shost)[2] = 1;
1527 fc_host_active_fc4s(shost)[7] = 1;
1528
1529 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001530 vport->fc_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04001531 spin_unlock_irq(shost->host_lock);
1532
1533 return 1;
1534}
dea31012005-04-17 16:05:31 -05001535
1536static int __devinit
1537lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1538{
James Smart2e0fef82007-06-17 19:56:36 -05001539 struct lpfc_vport *vport = NULL;
1540 struct lpfc_hba *phba;
1541 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001542 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001543 struct Scsi_Host *shost = NULL;
dea31012005-04-17 16:05:31 -05001544 unsigned long bar0map_len, bar2map_len;
1545 int error = -ENODEV, retval;
1546 int i;
James Bottomley604a3e32005-10-29 10:28:33 -05001547 uint16_t iotag;
dea31012005-04-17 16:05:31 -05001548
1549 if (pci_enable_device(pdev))
1550 goto out;
1551 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1552 goto out_disable_device;
1553
James Smart2e0fef82007-06-17 19:56:36 -05001554 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1555 if (!phba)
dea31012005-04-17 16:05:31 -05001556 goto out_release_regions;
1557
James Smart2e0fef82007-06-17 19:56:36 -05001558 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001559
dea31012005-04-17 16:05:31 -05001560 phba->pcidev = pdev;
1561
1562 /* Assign an unused board number */
1563 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
James Smart2e0fef82007-06-17 19:56:36 -05001564 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001565
1566 error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
1567 if (error)
James Smart2e0fef82007-06-17 19:56:36 -05001568 goto out_free_phba;
dea31012005-04-17 16:05:31 -05001569
James Smart2e0fef82007-06-17 19:56:36 -05001570 INIT_LIST_HEAD(&phba->port_list);
1571
1572 /*
1573 * Get all the module params for configuring this host and then
1574 * establish the host.
1575 */
1576 lpfc_get_cfgparam(phba);
dea31012005-04-17 16:05:31 -05001577
1578 /* Initialize timers used by driver */
1579 init_timer(&phba->fc_estabtmo);
1580 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
James Smart2e0fef82007-06-17 19:56:36 -05001581 phba->fc_estabtmo.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001582 psli = &phba->sli;
1583 init_timer(&psli->mbox_tmo);
1584 psli->mbox_tmo.function = lpfc_mbox_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001585 psli->mbox_tmo.data = (unsigned long) phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001586 init_timer(&phba->fcp_poll_timer);
1587 phba->fcp_poll_timer.function = lpfc_poll_timeout;
James Smart2e0fef82007-06-17 19:56:36 -05001588 phba->fcp_poll_timer.data = (unsigned long) phba;
dea31012005-04-17 16:05:31 -05001589
dea31012005-04-17 16:05:31 -05001590 pci_set_master(pdev);
1591 retval = pci_set_mwi(pdev);
1592 if (retval)
1593 dev_printk(KERN_WARNING, &pdev->dev,
1594 "Warning: pci_set_mwi returned %d\n", retval);
1595
1596 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
1597 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
1598 goto out_idr_remove;
1599
1600 /*
1601 * Get the bus address of Bar0 and Bar2 and the number of bytes
1602 * required by each mapping.
1603 */
1604 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
1605 bar0map_len = pci_resource_len(phba->pcidev, 0);
1606
1607 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
1608 bar2map_len = pci_resource_len(phba->pcidev, 2);
1609
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001610 /* Map HBA SLIM to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001611 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001612 if (!phba->slim_memmap_p) {
1613 error = -ENODEV;
1614 dev_printk(KERN_ERR, &pdev->dev,
1615 "ioremap failed for SLIM memory.\n");
1616 goto out_idr_remove;
1617 }
1618
1619 /* Map HBA Control Registers to a kernel virtual address. */
dea31012005-04-17 16:05:31 -05001620 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001621 if (!phba->ctrl_regs_memmap_p) {
1622 error = -ENODEV;
1623 dev_printk(KERN_ERR, &pdev->dev,
1624 "ioremap failed for HBA control registers.\n");
1625 goto out_iounmap_slim;
1626 }
dea31012005-04-17 16:05:31 -05001627
1628 /* Allocate memory for SLI-2 structures */
1629 phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1630 &phba->slim2p_mapping, GFP_KERNEL);
1631 if (!phba->slim2p)
1632 goto out_iounmap;
1633
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001634 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
dea31012005-04-17 16:05:31 -05001635
1636 /* Initialize the SLI Layer to run with lpfc HBAs. */
1637 lpfc_sli_setup(phba);
1638 lpfc_sli_queue_setup(phba);
1639
1640 error = lpfc_mem_alloc(phba);
1641 if (error)
1642 goto out_free_slim;
1643
1644 /* Initialize and populate the iocb list per host. */
1645 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
1646 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
1647 iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
1648 if (iocbq_entry == NULL) {
1649 printk(KERN_ERR "%s: only allocated %d iocbs of "
1650 "expected %d count. Unloading driver.\n",
1651 __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
1652 error = -ENOMEM;
1653 goto out_free_iocbq;
1654 }
1655
1656 memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
James Bottomley604a3e32005-10-29 10:28:33 -05001657 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
1658 if (iotag == 0) {
1659 kfree (iocbq_entry);
1660 printk(KERN_ERR "%s: failed to allocate IOTAG. "
1661 "Unloading driver.\n",
1662 __FUNCTION__);
1663 error = -ENOMEM;
1664 goto out_free_iocbq;
1665 }
James Smart2e0fef82007-06-17 19:56:36 -05001666
1667 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001668 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1669 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05001670 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001671 }
1672
1673 /* Initialize HBA structure */
1674 phba->fc_edtov = FF_DEF_EDTOV;
1675 phba->fc_ratov = FF_DEF_RATOV;
1676 phba->fc_altov = FF_DEF_ALTOV;
1677 phba->fc_arbtov = FF_DEF_ARBTOV;
1678
1679 INIT_LIST_HEAD(&phba->work_list);
1680 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
1681 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
1682
1683 /* Startup the kernel thread for this host adapter. */
1684 phba->worker_thread = kthread_run(lpfc_do_work, phba,
1685 "lpfc_worker_%d", phba->brd_no);
1686 if (IS_ERR(phba->worker_thread)) {
1687 error = PTR_ERR(phba->worker_thread);
1688 goto out_free_iocbq;
1689 }
1690
dea31012005-04-17 16:05:31 -05001691 /* Initialize the list of scsi buffers used by driver for scsi IO. */
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001692 spin_lock_init(&phba->scsi_buf_list_lock);
dea31012005-04-17 16:05:31 -05001693 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1694
James Smart2e0fef82007-06-17 19:56:36 -05001695 vport = lpfc_create_port(phba, phba->brd_no);
1696 if (!vport)
1697 goto out_kthread_stop;
1698
1699 shost = lpfc_shost_from_vport(vport);
1700 vport->port_type = LPFC_PHYSICAL_PORT;
1701 phba->pport = vport;
1702
1703 pci_set_drvdata(pdev, lpfc_shost_from_vport(vport));
dea31012005-04-17 16:05:31 -05001704
James Smart4ff43242006-12-02 13:34:56 -05001705 if (phba->cfg_use_msi) {
1706 error = pci_enable_msi(phba->pcidev);
1707 if (error)
1708 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "%d:0452 "
1709 "Enable MSI failed, continuing with "
1710 "IRQ\n", phba->brd_no);
1711 }
1712
Thomas Gleixner1d6f3592006-07-01 19:29:42 -07001713 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
James Smart2e0fef82007-06-17 19:56:36 -05001714 LPFC_DRIVER_NAME, phba);
dea31012005-04-17 16:05:31 -05001715 if (error) {
1716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1717 "%d:0451 Enable interrupt handler failed\n",
1718 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05001719 goto out_destroy_port;
dea31012005-04-17 16:05:31 -05001720 }
dea31012005-04-17 16:05:31 -05001721
James Smart2e0fef82007-06-17 19:56:36 -05001722 phba->MBslimaddr = phba->slim_memmap_p;
1723 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1724 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1725 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1726 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1727
1728 error = lpfc_sli_hba_setup(phba);
James Smart47a86172007-04-25 09:53:22 -04001729 if (error)
dea31012005-04-17 16:05:31 -05001730 goto out_free_irq;
1731
James Smart2e0fef82007-06-17 19:56:36 -05001732 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1733 spin_lock_irq(shost->host_lock);
1734 lpfc_poll_start_timer(phba);
1735 spin_unlock_irq(shost->host_lock);
1736 }
James Smart8f6d98d2006-08-01 07:34:00 -04001737
dea31012005-04-17 16:05:31 -05001738 return 0;
1739
1740out_free_irq:
1741 lpfc_stop_timer(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001742 phba->pport->work_port_events = 0;
dea31012005-04-17 16:05:31 -05001743 free_irq(phba->pcidev->irq, phba);
James Smart4ff43242006-12-02 13:34:56 -05001744 pci_disable_msi(phba->pcidev);
James Smart2e0fef82007-06-17 19:56:36 -05001745out_destroy_port:
1746 destroy_port(vport);
dea31012005-04-17 16:05:31 -05001747out_kthread_stop:
1748 kthread_stop(phba->worker_thread);
1749out_free_iocbq:
1750 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1751 &phba->lpfc_iocb_list, list) {
dea31012005-04-17 16:05:31 -05001752 kfree(iocbq_entry);
1753 phba->total_iocbq_bufs--;
dea31012005-04-17 16:05:31 -05001754 }
1755 lpfc_mem_free(phba);
1756out_free_slim:
1757 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1758 phba->slim2p_mapping);
1759out_iounmap:
1760 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05001761out_iounmap_slim:
dea31012005-04-17 16:05:31 -05001762 iounmap(phba->slim_memmap_p);
1763out_idr_remove:
1764 idr_remove(&lpfc_hba_index, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05001765out_free_phba:
1766 kfree(phba);
dea31012005-04-17 16:05:31 -05001767out_release_regions:
1768 pci_release_regions(pdev);
1769out_disable_device:
1770 pci_disable_device(pdev);
1771out:
James Smartdefbcf12006-04-16 22:26:50 -04001772 pci_set_drvdata(pdev, NULL);
dea31012005-04-17 16:05:31 -05001773 return error;
1774}
1775
1776static void __devexit
1777lpfc_pci_remove_one(struct pci_dev *pdev)
1778{
James Smart2e0fef82007-06-17 19:56:36 -05001779 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1780 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1781 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001782
James Smart2e0fef82007-06-17 19:56:36 -05001783 vport->load_flag |= FC_UNLOADING;
1784 lpfc_remove_device(vport);
1785
1786 /*
1787 * Bring down the SLI Layer. This step disable all interrupts,
1788 * clears the rings, discards all mailbox commands, and resets
1789 * the HBA.
1790 */
1791 lpfc_sli_hba_down(phba);
1792 lpfc_sli_brdrestart(phba);
1793
1794 lpfc_stop_timer(phba);
1795
1796 kthread_stop(phba->worker_thread);
1797
1798 /* Release the irq reservation */
1799 free_irq(phba->pcidev->irq, phba);
1800 pci_disable_msi(phba->pcidev);
1801
1802 vport->work_port_events = 0;
1803 destroy_port(vport);
dea31012005-04-17 16:05:31 -05001804
1805 pci_set_drvdata(pdev, NULL);
James Smart2e0fef82007-06-17 19:56:36 -05001806
1807 /*
1808 * Call scsi_free before mem_free since scsi bufs are released to their
1809 * corresponding pools here.
1810 */
1811 lpfc_scsi_free(phba);
1812 lpfc_mem_free(phba);
1813
1814 /* Free resources associated with SLI2 interface */
1815 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
1816 phba->slim2p, phba->slim2p_mapping);
1817
1818 /* unmap adapter SLIM and Control Registers */
1819 iounmap(phba->ctrl_regs_memmap_p);
1820 iounmap(phba->slim_memmap_p);
1821
1822 idr_remove(&lpfc_hba_index, phba->brd_no);
1823
1824 kfree(phba);
1825
1826 pci_release_regions(pdev);
1827 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05001828}
1829
Linas Vepstas8d63f372007-02-14 14:28:36 -06001830/**
1831 * lpfc_io_error_detected - called when PCI error is detected
1832 * @pdev: Pointer to PCI device
1833 * @state: The current pci conneection state
1834 *
1835 * This function is called after a PCI bus error affecting
1836 * this device has been detected.
1837 */
1838static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
1839 pci_channel_state_t state)
1840{
1841 struct Scsi_Host *host = pci_get_drvdata(pdev);
1842 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1843 struct lpfc_sli *psli = &phba->sli;
1844 struct lpfc_sli_ring *pring;
1845
Linas Vepstas5daa49e2007-03-08 16:19:11 -06001846 if (state == pci_channel_io_perm_failure)
Linas Vepstas8d63f372007-02-14 14:28:36 -06001847 return PCI_ERS_RESULT_DISCONNECT;
Linas Vepstas5daa49e2007-03-08 16:19:11 -06001848
Linas Vepstas8d63f372007-02-14 14:28:36 -06001849 pci_disable_device(pdev);
1850 /*
1851 * There may be I/Os dropped by the firmware.
1852 * Error iocb (I/O) on txcmplq and let the SCSI layer
1853 * retry it after re-establishing link.
1854 */
1855 pring = &psli->ring[psli->fcp_ring];
1856 lpfc_sli_abort_iocb_ring(phba, pring);
1857
1858 /* Request a slot reset. */
1859 return PCI_ERS_RESULT_NEED_RESET;
1860}
1861
1862/**
1863 * lpfc_io_slot_reset - called after the pci bus has been reset.
1864 * @pdev: Pointer to PCI device
1865 *
1866 * Restart the card from scratch, as if from a cold-boot.
1867 */
1868static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
1869{
1870 struct Scsi_Host *host = pci_get_drvdata(pdev);
1871 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1872 struct lpfc_sli *psli = &phba->sli;
1873 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1874
1875 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
1876 if (pci_enable_device_bars(pdev, bars)) {
1877 printk(KERN_ERR "lpfc: Cannot re-enable "
1878 "PCI device after reset.\n");
1879 return PCI_ERS_RESULT_DISCONNECT;
1880 }
1881
1882 pci_set_master(pdev);
1883
1884 /* Re-establishing Link */
James Smart2e0fef82007-06-17 19:56:36 -05001885 spin_lock_irq(&phba->hbalock);
1886 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
1887 spin_unlock_irq(&phba->hbalock);
1888 spin_lock_irq(host->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001889 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart2e0fef82007-06-17 19:56:36 -05001890 spin_unlock_irq(host->host_lock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001891
1892
1893 /* Take device offline; this will perform cleanup */
1894 lpfc_offline(phba);
1895 lpfc_sli_brdrestart(phba);
1896
1897 return PCI_ERS_RESULT_RECOVERED;
1898}
1899
1900/**
1901 * lpfc_io_resume - called when traffic can start flowing again.
1902 * @pdev: Pointer to PCI device
1903 *
1904 * This callback is called when the error recovery driver tells us that
1905 * its OK to resume normal operation.
1906 */
1907static void lpfc_io_resume(struct pci_dev *pdev)
1908{
1909 struct Scsi_Host *host = pci_get_drvdata(pdev);
1910 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1911
1912 if (lpfc_online(phba) == 0) {
1913 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
1914 }
1915}
1916
dea31012005-04-17 16:05:31 -05001917static struct pci_device_id lpfc_id_table[] = {
1918 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1919 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001920 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
1921 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05001922 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
1923 PCI_ANY_ID, PCI_ANY_ID, },
1924 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
1925 PCI_ANY_ID, PCI_ANY_ID, },
1926 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
1927 PCI_ANY_ID, PCI_ANY_ID, },
1928 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
1929 PCI_ANY_ID, PCI_ANY_ID, },
1930 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
1931 PCI_ANY_ID, PCI_ANY_ID, },
1932 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
1933 PCI_ANY_ID, PCI_ANY_ID, },
1934 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
1935 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001936 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
1937 PCI_ANY_ID, PCI_ANY_ID, },
1938 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
1939 PCI_ANY_ID, PCI_ANY_ID, },
1940 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
1941 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05001942 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
1943 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001944 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
1945 PCI_ANY_ID, PCI_ANY_ID, },
1946 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
1947 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05001948 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
1949 PCI_ANY_ID, PCI_ANY_ID, },
1950 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
1951 PCI_ANY_ID, PCI_ANY_ID, },
1952 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
1953 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001954 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
1955 PCI_ANY_ID, PCI_ANY_ID, },
1956 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
1957 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05001958 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
1959 PCI_ANY_ID, PCI_ANY_ID, },
1960 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
1961 PCI_ANY_ID, PCI_ANY_ID, },
1962 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
1963 PCI_ANY_ID, PCI_ANY_ID, },
1964 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
1965 PCI_ANY_ID, PCI_ANY_ID, },
1966 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
1967 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001968 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
1969 PCI_ANY_ID, PCI_ANY_ID, },
1970 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
1971 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04001972 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
1973 PCI_ANY_ID, PCI_ANY_ID, },
1974 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
1975 PCI_ANY_ID, PCI_ANY_ID, },
1976 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
1977 PCI_ANY_ID, PCI_ANY_ID, },
1978 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
1979 PCI_ANY_ID, PCI_ANY_ID, },
1980 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
1981 PCI_ANY_ID, PCI_ANY_ID, },
1982 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
1983 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05001984 { 0 }
1985};
1986
1987MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1988
Linas Vepstas8d63f372007-02-14 14:28:36 -06001989static struct pci_error_handlers lpfc_err_handler = {
1990 .error_detected = lpfc_io_error_detected,
1991 .slot_reset = lpfc_io_slot_reset,
1992 .resume = lpfc_io_resume,
1993};
1994
dea31012005-04-17 16:05:31 -05001995static struct pci_driver lpfc_driver = {
1996 .name = LPFC_DRIVER_NAME,
1997 .id_table = lpfc_id_table,
1998 .probe = lpfc_pci_probe_one,
1999 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart2e0fef82007-06-17 19:56:36 -05002000 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05002001};
2002
2003static int __init
2004lpfc_init(void)
2005{
2006 int error = 0;
2007
2008 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04002009 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05002010
2011 lpfc_transport_template =
2012 fc_attach_transport(&lpfc_transport_functions);
2013 if (!lpfc_transport_template)
2014 return -ENOMEM;
2015 error = pci_register_driver(&lpfc_driver);
2016 if (error)
2017 fc_release_transport(lpfc_transport_template);
2018
2019 return error;
2020}
2021
2022static void __exit
2023lpfc_exit(void)
2024{
2025 pci_unregister_driver(&lpfc_driver);
2026 fc_release_transport(lpfc_transport_template);
2027}
2028
2029module_init(lpfc_init);
2030module_exit(lpfc_exit);
2031MODULE_LICENSE("GPL");
2032MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2033MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2034MODULE_VERSION("0:" LPFC_DRIVER_VERSION);