blob: 3f06ce2becf5d730e0915292275140a211c7b3ae [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
27#include <linux/kthread.h>
28#include <linux/pci.h>
29#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050030#include <linux/ctype.h>
dea31012005-04-17 16:05:31 -050031
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040032#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050033#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
36
37#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040039#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_disc.h"
41#include "lpfc_scsi.h"
42#include "lpfc.h"
43#include "lpfc_logmsg.h"
44#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050045#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050046#include "lpfc_version.h"
47
James Smart81301a92008-12-04 22:39:46 -050048char *_dump_buf_data;
49unsigned long _dump_buf_data_order;
50char *_dump_buf_dif;
51unsigned long _dump_buf_dif_order;
52spinlock_t _dump_buf_lock;
53
Jamie Wellnitz74b72a52006-02-28 22:33:04 -050054static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
dea31012005-04-17 16:05:31 -050055static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
56static int lpfc_post_rcv_buf(struct lpfc_hba *);
57
58static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050059static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050060static DEFINE_IDR(lpfc_hba_index);
61
James Smarte59058c2008-08-24 21:49:00 -040062/**
James Smart3621a712009-04-06 18:47:14 -040063 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040064 * @phba: pointer to lpfc hba data structure.
65 *
66 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
67 * mailbox command. It retrieves the revision information from the HBA and
68 * collects the Vital Product Data (VPD) about the HBA for preparing the
69 * configuration of the HBA.
70 *
71 * Return codes:
72 * 0 - success.
73 * -ERESTART - requests the SLI layer to reset the HBA and try again.
74 * Any other value - indicates an error.
75 **/
dea31012005-04-17 16:05:31 -050076int
James Smart2e0fef82007-06-17 19:56:36 -050077lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -050078{
79 lpfc_vpd_t *vp = &phba->vpd;
80 int i = 0, rc;
81 LPFC_MBOXQ_t *pmb;
82 MAILBOX_t *mb;
83 char *lpfc_vpd_data = NULL;
84 uint16_t offset = 0;
85 static char licensed[56] =
86 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -040087 static int init_key = 1;
dea31012005-04-17 16:05:31 -050088
89 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
90 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -050091 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050092 return -ENOMEM;
93 }
94
95 mb = &pmb->mb;
James Smart2e0fef82007-06-17 19:56:36 -050096 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -050097
98 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -040099 if (init_key) {
100 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500101
James Smart65a29c12006-07-06 15:50:50 -0400102 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
103 *ptext = cpu_to_be32(*ptext);
104 init_key = 0;
105 }
dea31012005-04-17 16:05:31 -0500106
107 lpfc_read_nv(phba, pmb);
108 memset((char*)mb->un.varRDnvp.rsvd3, 0,
109 sizeof (mb->un.varRDnvp.rsvd3));
110 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
111 sizeof (licensed));
112
113 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
114
115 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400117 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500118 "error, mbxCmd x%x READ_NVPARM, "
119 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500120 mb->mbxCommand, mb->mbxStatus);
121 mempool_free(pmb, phba->mbox_mem_pool);
122 return -ERESTART;
123 }
124 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500125 sizeof(phba->wwnn));
126 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
127 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500128 }
129
James Smart92d7f7b2007-06-17 19:56:38 -0500130 phba->sli3_options = 0x0;
131
dea31012005-04-17 16:05:31 -0500132 /* Setup and issue mailbox READ REV command */
133 lpfc_read_rev(phba, pmb);
134 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
135 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400137 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500138 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500139 mb->mbxCommand, mb->mbxStatus);
140 mempool_free( pmb, phba->mbox_mem_pool);
141 return -ERESTART;
142 }
143
James Smart92d7f7b2007-06-17 19:56:38 -0500144
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500145 /*
146 * The value of rr must be 1 since the driver set the cv field to 1.
147 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500148 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500149 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500150 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400152 "0440 Adapter failed to init, READ_REV has "
153 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500154 mempool_free(pmb, phba->mbox_mem_pool);
155 return -ERESTART;
dea31012005-04-17 16:05:31 -0500156 }
157
James Smart495a7142008-06-14 22:52:59 -0400158 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
159 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500160 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400161 }
James Smarted957682007-06-17 19:56:37 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500164 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500165 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500166 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
167 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
168 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
169 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500170 vp->rev.biuRev = mb->un.varRdRev.biuRev;
171 vp->rev.smRev = mb->un.varRdRev.smRev;
172 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
173 vp->rev.endecRev = mb->un.varRdRev.endecRev;
174 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
175 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
176 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
177 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
178 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
179 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
180
James Smart92d7f7b2007-06-17 19:56:38 -0500181 /* If the sli feature level is less then 9, we must
182 * tear down all RPIs and VPIs on link down if NPIV
183 * is enabled.
184 */
185 if (vp->rev.feaLevelHigh < 9)
186 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
187
dea31012005-04-17 16:05:31 -0500188 if (lpfc_is_LC_HBA(phba->pcidev->device))
189 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
190 sizeof (phba->RandomData));
191
dea31012005-04-17 16:05:31 -0500192 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500193 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
194 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400195 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500196
197 do {
198 lpfc_dump_mem(phba, pmb, offset);
199 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
200
201 if (rc != MBX_SUCCESS) {
202 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400203 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500204 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500205 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500206 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500207 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500208 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
209 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400210 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
211 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500212 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500213 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500214 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
215 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500216
217 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500218out_free_mbox:
219 mempool_free(pmb, phba->mbox_mem_pool);
220 return 0;
221}
222
James Smarte59058c2008-08-24 21:49:00 -0400223/**
James Smart3621a712009-04-06 18:47:14 -0400224 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400225 * @phba: pointer to lpfc hba data structure.
226 * @pmboxq: pointer to the driver internal queue element for mailbox command.
227 *
228 * This is the completion handler for driver's configuring asynchronous event
229 * mailbox command to the device. If the mailbox command returns successfully,
230 * it will set internal async event support flag to 1; otherwise, it will
231 * set internal async event support flag to 0.
232 **/
James Smart57127f12007-10-27 13:37:05 -0400233static void
234lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
235{
236 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
237 phba->temp_sensor_support = 1;
238 else
239 phba->temp_sensor_support = 0;
240 mempool_free(pmboxq, phba->mbox_mem_pool);
241 return;
242}
243
James Smarte59058c2008-08-24 21:49:00 -0400244/**
James Smart3621a712009-04-06 18:47:14 -0400245 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500246 * @phba: pointer to lpfc hba data structure.
247 * @pmboxq: pointer to the driver internal queue element for mailbox command.
248 *
249 * This is the completion handler for dump mailbox command for getting
250 * wake up parameters. When this command complete, the response contain
251 * Option rom version of the HBA. This function translate the version number
252 * into a human readable string and store it in OptionROMVersion.
253 **/
254static void
255lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
256{
257 struct prog_id *prg;
258 uint32_t prog_id_word;
259 char dist = ' ';
260 /* character array used for decoding dist type. */
261 char dist_char[] = "nabx";
262
James Smart9f1e1b52008-12-04 22:39:40 -0500263 if (pmboxq->mb.mbxStatus != MBX_SUCCESS) {
264 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500265 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500266 }
James Smart97207482008-12-04 22:39:19 -0500267
268 prg = (struct prog_id *) &prog_id_word;
269
270 /* word 7 contain option rom version */
271 prog_id_word = pmboxq->mb.un.varWords[7];
272
273 /* Decode the Option rom version word to a readable string */
274 if (prg->dist < 4)
275 dist = dist_char[prg->dist];
276
277 if ((prg->dist == 3) && (prg->num == 0))
278 sprintf(phba->OptionROMVersion, "%d.%d%d",
279 prg->ver, prg->rev, prg->lev);
280 else
281 sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
282 prg->ver, prg->rev, prg->lev,
283 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500284 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500285 return;
286}
287
288/**
James Smart3621a712009-04-06 18:47:14 -0400289 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400290 * @phba: pointer to lpfc hba data structure.
291 *
292 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
293 * command call. It performs all internal resource and state setups on the
294 * port: post IOCB buffers, enable appropriate host interrupt attentions,
295 * ELS ring timers, etc.
296 *
297 * Return codes
298 * 0 - success.
299 * Any other value - error.
300 **/
dea31012005-04-17 16:05:31 -0500301int
James Smart2e0fef82007-06-17 19:56:36 -0500302lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500303{
James Smart2e0fef82007-06-17 19:56:36 -0500304 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500306 LPFC_MBOXQ_t *pmb;
307 MAILBOX_t *mb;
308 struct lpfc_dmabuf *mp;
309 struct lpfc_sli *psli = &phba->sli;
310 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500311 int i, j;
312 int rc;
dea31012005-04-17 16:05:31 -0500313
James Smart7af67052007-10-27 13:38:11 -0400314 spin_lock_irq(&phba->hbalock);
315 /*
316 * If the Config port completed correctly the HBA is not
317 * over heated any more.
318 */
319 if (phba->over_temp_state == HBA_OVER_TEMP)
320 phba->over_temp_state = HBA_NORMAL_TEMP;
321 spin_unlock_irq(&phba->hbalock);
322
dea31012005-04-17 16:05:31 -0500323 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
324 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500325 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500326 return -ENOMEM;
327 }
328 mb = &pmb->mb;
329
dea31012005-04-17 16:05:31 -0500330 /* Get login parameters for NID. */
James Smart92d7f7b2007-06-17 19:56:38 -0500331 lpfc_read_sparam(phba, pmb, 0);
James Smarted957682007-06-17 19:56:37 -0500332 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500333 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400335 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500336 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500337 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500338 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500339 mp = (struct lpfc_dmabuf *) pmb->context1;
340 mempool_free( pmb, phba->mbox_mem_pool);
341 lpfc_mbuf_free(phba, mp->virt, mp->phys);
342 kfree(mp);
343 return -EIO;
344 }
345
346 mp = (struct lpfc_dmabuf *) pmb->context1;
347
James Smart2e0fef82007-06-17 19:56:36 -0500348 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500349 lpfc_mbuf_free(phba, mp->virt, mp->phys);
350 kfree(mp);
351 pmb->context1 = NULL;
352
James Smarta12e07b2006-12-02 13:35:30 -0500353 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500354 u64_to_wwn(phba->cfg_soft_wwnn,
355 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400356 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500357 u64_to_wwn(phba->cfg_soft_wwpn,
358 vport->fc_sparam.portName.u.wwn);
359 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500360 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500361 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500362 sizeof (struct lpfc_name));
James Smarta257bf92009-04-06 18:48:10 -0400363
364 /* Update the fc_host data structures with new wwn. */
365 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
366 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
367
dea31012005-04-17 16:05:31 -0500368 /* If no serial number in VPD data, use low 6 bytes of WWNN */
369 /* This should be consolidated into parse_vpd ? - mr */
370 if (phba->SerialNumber[0] == 0) {
371 uint8_t *outptr;
372
James Smart2e0fef82007-06-17 19:56:36 -0500373 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500374 for (i = 0; i < 12; i++) {
375 status = *outptr++;
376 j = ((status & 0xf0) >> 4);
377 if (j <= 9)
378 phba->SerialNumber[i] =
379 (char)((uint8_t) 0x30 + (uint8_t) j);
380 else
381 phba->SerialNumber[i] =
382 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
383 i++;
384 j = (status & 0xf);
385 if (j <= 9)
386 phba->SerialNumber[i] =
387 (char)((uint8_t) 0x30 + (uint8_t) j);
388 else
389 phba->SerialNumber[i] =
390 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
391 }
392 }
393
dea31012005-04-17 16:05:31 -0500394 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500395 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500396 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400398 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500399 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500400 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500401 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500402 mempool_free( pmb, phba->mbox_mem_pool);
403 return -EIO;
404 }
405
406 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
407 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
408 phba->cfg_hba_queue_depth =
409 mb->un.varRdConfig.max_xri + 1;
410
411 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500412
413 /* Get the default values for Model Name and Description */
414 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
415
416 if ((phba->cfg_link_speed > LINK_SPEED_10G)
417 || ((phba->cfg_link_speed == LINK_SPEED_1G)
418 && !(phba->lmt & LMT_1Gb))
419 || ((phba->cfg_link_speed == LINK_SPEED_2G)
420 && !(phba->lmt & LMT_2Gb))
421 || ((phba->cfg_link_speed == LINK_SPEED_4G)
422 && !(phba->lmt & LMT_4Gb))
423 || ((phba->cfg_link_speed == LINK_SPEED_8G)
424 && !(phba->lmt & LMT_8Gb))
425 || ((phba->cfg_link_speed == LINK_SPEED_10G)
426 && !(phba->lmt & LMT_10Gb))) {
427 /* Reset link speed to auto */
James Smarted957682007-06-17 19:56:37 -0500428 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400429 "1302 Invalid speed for this board: "
dea31012005-04-17 16:05:31 -0500430 "Reset link speed to auto: x%x\n",
dea31012005-04-17 16:05:31 -0500431 phba->cfg_link_speed);
432 phba->cfg_link_speed = LINK_SPEED_AUTO;
433 }
434
James Smart2e0fef82007-06-17 19:56:36 -0500435 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500436
James Smart0b727fe2007-10-27 13:37:25 -0400437 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smarta4bc3372006-12-02 13:34:16 -0500438 if (psli->ring[psli->extra_ring].cmdringaddr)
439 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500440 if (psli->ring[psli->fcp_ring].cmdringaddr)
441 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
442 if (psli->ring[psli->next_ring].cmdringaddr)
443 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
444
445 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500446 if (phba->sli_rev != 3)
447 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500448
James Smart93996272008-08-24 21:50:30 -0400449 /*
450 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
451 */
452 if (phba->intr_type == MSIX) {
453 rc = lpfc_config_msi(phba, pmb);
454 if (rc) {
455 mempool_free(pmb, phba->mbox_mem_pool);
456 return -EIO;
457 }
458 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
459 if (rc != MBX_SUCCESS) {
460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
461 "0352 Config MSI mailbox command "
462 "failed, mbxCmd x%x, mbxStatus x%x\n",
463 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
464 mempool_free(pmb, phba->mbox_mem_pool);
465 return -EIO;
466 }
467 }
468
469 /* Initialize ERATT handling flag */
470 phba->hba_flag &= ~HBA_ERATT_HANDLED;
471
dea31012005-04-17 16:05:31 -0500472 /* Enable appropriate host interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500473 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500474 status = readl(phba->HCregaddr);
475 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
476 if (psli->num_rings > 0)
477 status |= HC_R0INT_ENA;
478 if (psli->num_rings > 1)
479 status |= HC_R1INT_ENA;
480 if (psli->num_rings > 2)
481 status |= HC_R2INT_ENA;
482 if (psli->num_rings > 3)
483 status |= HC_R3INT_ENA;
484
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500485 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
486 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400487 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500488
dea31012005-04-17 16:05:31 -0500489 writel(status, phba->HCregaddr);
490 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500491 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500492
James Smart93996272008-08-24 21:50:30 -0400493 /* Set up ring-0 (ELS) timer */
494 timeout = phba->fc_ratov * 2;
James Smart2e0fef82007-06-17 19:56:36 -0500495 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
James Smart93996272008-08-24 21:50:30 -0400496 /* Set up heart beat (HB) timer */
James Smart858c9f62007-06-17 19:56:39 -0500497 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
498 phba->hb_outstanding = 0;
499 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400500 /* Set up error attention (ERATT) polling timer */
501 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
dea31012005-04-17 16:05:31 -0500502
503 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
504 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart5b8bd0c2007-04-25 09:52:49 -0400505 lpfc_set_loopback_flag(phba);
James Smartd7c255b2008-08-24 21:50:00 -0400506 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
James Smart8aee9182006-08-31 12:27:57 -0400507 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400509 "0454 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500510 "INIT_LINK, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500511 mb->mbxCommand, mb->mbxStatus);
512
513 /* Clear all interrupt enable conditions */
514 writel(0, phba->HCregaddr);
515 readl(phba->HCregaddr); /* flush */
516 /* Clear all pending interrupts */
517 writel(0xffffffff, phba->HAregaddr);
518 readl(phba->HAregaddr); /* flush */
519
James Smart2e0fef82007-06-17 19:56:36 -0500520 phba->link_state = LPFC_HBA_ERROR;
James Smart8aee9182006-08-31 12:27:57 -0400521 if (rc != MBX_BUSY)
522 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500523 return -EIO;
524 }
525 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400526 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
527 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
528 pmb->mbox_cmpl = lpfc_config_async_cmpl;
529 pmb->vport = phba->pport;
530 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500531
James Smart57127f12007-10-27 13:37:05 -0400532 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
533 lpfc_printf_log(phba,
534 KERN_ERR,
535 LOG_INIT,
536 "0456 Adapter failed to issue "
537 "ASYNCEVT_ENABLE mbox status x%x \n.",
538 rc);
539 mempool_free(pmb, phba->mbox_mem_pool);
540 }
James Smart97207482008-12-04 22:39:19 -0500541
542 /* Get Option rom version */
543 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
544 lpfc_dump_wakeup_param(phba, pmb);
545 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
546 pmb->vport = phba->pport;
547 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
548
549 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
550 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
551 "to get Option ROM version status x%x\n.", rc);
552 mempool_free(pmb, phba->mbox_mem_pool);
553 }
554
James Smartd7c255b2008-08-24 21:50:00 -0400555 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400556}
557
James Smarte59058c2008-08-24 21:49:00 -0400558/**
James Smart3621a712009-04-06 18:47:14 -0400559 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400560 * @phba: pointer to lpfc HBA data structure.
561 *
562 * This routine will do LPFC uninitialization before the HBA is reset when
563 * bringing down the SLI Layer.
564 *
565 * Return codes
566 * 0 - success.
567 * Any other value - error.
568 **/
dea31012005-04-17 16:05:31 -0500569int
James Smart2e0fef82007-06-17 19:56:36 -0500570lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500571{
James Smart1b32f6a2008-02-08 18:49:39 -0500572 struct lpfc_vport **vports;
573 int i;
James Smart3772a992009-05-22 14:50:54 -0400574
575 if (phba->sli_rev <= LPFC_SLI_REV3) {
576 /* Disable interrupts */
577 writel(0, phba->HCregaddr);
578 readl(phba->HCregaddr); /* flush */
579 }
dea31012005-04-17 16:05:31 -0500580
James Smart1b32f6a2008-02-08 18:49:39 -0500581 if (phba->pport->load_flag & FC_UNLOADING)
582 lpfc_cleanup_discovery_resources(phba->pport);
583 else {
584 vports = lpfc_create_vport_work_array(phba);
585 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400586 for (i = 0; i <= phba->max_vports &&
587 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500588 lpfc_cleanup_discovery_resources(vports[i]);
589 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500590 }
591 return 0;
dea31012005-04-17 16:05:31 -0500592}
593
James Smarte59058c2008-08-24 21:49:00 -0400594/**
James Smart3772a992009-05-22 14:50:54 -0400595 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400596 * @phba: pointer to lpfc HBA data structure.
597 *
598 * This routine will do uninitialization after the HBA is reset when bring
599 * down the SLI Layer.
600 *
601 * Return codes
602 * 0 - sucess.
603 * Any other value - error.
604 **/
James Smart3772a992009-05-22 14:50:54 -0400605static int
606lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500607{
608 struct lpfc_sli *psli = &phba->sli;
609 struct lpfc_sli_ring *pring;
610 struct lpfc_dmabuf *mp, *next_mp;
James Smart09372822008-01-11 01:52:54 -0500611 LIST_HEAD(completions);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500612 int i;
613
James Smart92d7f7b2007-06-17 19:56:38 -0500614 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
615 lpfc_sli_hbqbuf_free_all(phba);
616 else {
617 /* Cleanup preposted buffers on the ELS ring */
618 pring = &psli->ring[LPFC_ELS_RING];
619 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
620 list_del(&mp->list);
621 pring->postbufq_cnt--;
622 lpfc_mbuf_free(phba, mp->virt, mp->phys);
623 kfree(mp);
624 }
Jamie Wellnitz41415862006-02-28 19:25:27 -0500625 }
626
James Smart09372822008-01-11 01:52:54 -0500627 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500628 for (i = 0; i < psli->num_rings; i++) {
629 pring = &psli->ring[i];
James Smart09372822008-01-11 01:52:54 -0500630
631 /* At this point in time the HBA is either reset or DOA. Either
632 * way, nothing should be on txcmplq as it will NEVER complete.
633 */
634 list_splice_init(&pring->txcmplq, &completions);
635 pring->txcmplq_cnt = 0;
636 spin_unlock_irq(&phba->hbalock);
637
James Smarta257bf92009-04-06 18:48:10 -0400638 /* Cancel all the IOCBs from the completions list */
639 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
640 IOERR_SLI_ABORTED);
James Smart09372822008-01-11 01:52:54 -0500641
Jamie Wellnitz41415862006-02-28 19:25:27 -0500642 lpfc_sli_abort_iocb_ring(phba, pring);
James Smart09372822008-01-11 01:52:54 -0500643 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500644 }
James Smart09372822008-01-11 01:52:54 -0500645 spin_unlock_irq(&phba->hbalock);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500646
647 return 0;
648}
649
James Smarte59058c2008-08-24 21:49:00 -0400650/**
James Smart3621a712009-04-06 18:47:14 -0400651 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400652 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
653 *
654 * This is the HBA-timer timeout handler registered to the lpfc driver. When
655 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
656 * work-port-events bitmap and the worker thread is notified. This timeout
657 * event will be used by the worker thread to invoke the actual timeout
658 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
659 * be performed in the timeout handler and the HBA timeout event bit shall
660 * be cleared by the worker thread after it has taken the event bitmap out.
661 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +0100662static void
James Smart858c9f62007-06-17 19:56:39 -0500663lpfc_hb_timeout(unsigned long ptr)
664{
665 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -0400666 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -0500667 unsigned long iflag;
668
669 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -0400670
671 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -0500672 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -0400673 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
674 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -0500675 phba->pport->work_port_events |= WORKER_HB_TMO;
676 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
677
James Smart93996272008-08-24 21:50:30 -0400678 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -0400679 if (!tmo_posted)
680 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -0500681 return;
682}
683
James Smarte59058c2008-08-24 21:49:00 -0400684/**
James Smart3621a712009-04-06 18:47:14 -0400685 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -0400686 * @phba: pointer to lpfc hba data structure.
687 * @pmboxq: pointer to the driver internal queue element for mailbox command.
688 *
689 * This is the callback function to the lpfc heart-beat mailbox command.
690 * If configured, the lpfc driver issues the heart-beat mailbox command to
691 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
692 * heart-beat mailbox command is issued, the driver shall set up heart-beat
693 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
694 * heart-beat outstanding state. Once the mailbox command comes back and
695 * no error conditions detected, the heart-beat mailbox command timer is
696 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
697 * state is cleared for the next heart-beat. If the timer expired with the
698 * heart-beat outstanding state set, the driver will put the HBA offline.
699 **/
James Smart858c9f62007-06-17 19:56:39 -0500700static void
701lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
702{
703 unsigned long drvr_flag;
704
705 spin_lock_irqsave(&phba->hbalock, drvr_flag);
706 phba->hb_outstanding = 0;
707 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
708
James Smart93996272008-08-24 21:50:30 -0400709 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -0500710 mempool_free(pmboxq, phba->mbox_mem_pool);
711 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
712 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -0400713 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -0500714 mod_timer(&phba->hb_tmofunc,
715 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
716 return;
717}
718
James Smarte59058c2008-08-24 21:49:00 -0400719/**
James Smart3621a712009-04-06 18:47:14 -0400720 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -0400721 * @phba: pointer to lpfc hba data structure.
722 *
723 * This is the actual HBA-timer timeout handler to be invoked by the worker
724 * thread whenever the HBA timer fired and HBA-timeout event posted. This
725 * handler performs any periodic operations needed for the device. If such
726 * periodic event has already been attended to either in the interrupt handler
727 * or by processing slow-ring or fast-ring events within the HBA-timer
728 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
729 * the timer for the next timeout period. If lpfc heart-beat mailbox command
730 * is configured and there is no heart-beat mailbox command outstanding, a
731 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
732 * has been a heart-beat mailbox command outstanding, the HBA shall be put
733 * to offline.
734 **/
James Smart858c9f62007-06-17 19:56:39 -0500735void
736lpfc_hb_timeout_handler(struct lpfc_hba *phba)
737{
738 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -0500739 struct lpfc_dmabuf *buf_ptr;
James Smart858c9f62007-06-17 19:56:39 -0500740 int retval;
741 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -0500742 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -0500743
744 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -0400745 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -0500746 (phba->pport->fc_flag & FC_OFFLINE_MODE))
747 return;
748
749 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -0500750
751 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
752 jiffies)) {
753 spin_unlock_irq(&phba->pport->work_port_lock);
754 if (!phba->hb_outstanding)
755 mod_timer(&phba->hb_tmofunc,
756 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
757 else
758 mod_timer(&phba->hb_tmofunc,
759 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
760 return;
761 }
762 spin_unlock_irq(&phba->pport->work_port_lock);
763
James Smart0ff10d42008-01-11 01:52:36 -0500764 if (phba->elsbuf_cnt &&
765 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
766 spin_lock_irq(&phba->hbalock);
767 list_splice_init(&phba->elsbuf, &completions);
768 phba->elsbuf_cnt = 0;
769 phba->elsbuf_prev_cnt = 0;
770 spin_unlock_irq(&phba->hbalock);
771
772 while (!list_empty(&completions)) {
773 list_remove_head(&completions, buf_ptr,
774 struct lpfc_dmabuf, list);
775 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
776 kfree(buf_ptr);
777 }
778 }
779 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
780
James Smart858c9f62007-06-17 19:56:39 -0500781 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -0500782 if (phba->cfg_enable_hba_heartbeat) {
783 if (!phba->hb_outstanding) {
784 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
785 if (!pmboxq) {
786 mod_timer(&phba->hb_tmofunc,
787 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
788 return;
789 }
790
791 lpfc_heart_beat(phba, pmboxq);
792 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
793 pmboxq->vport = phba->pport;
794 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
795
796 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
797 mempool_free(pmboxq, phba->mbox_mem_pool);
798 mod_timer(&phba->hb_tmofunc,
799 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
800 return;
801 }
James Smart858c9f62007-06-17 19:56:39 -0500802 mod_timer(&phba->hb_tmofunc,
James Smart13815c82008-01-11 01:52:48 -0500803 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
804 phba->hb_outstanding = 1;
James Smart858c9f62007-06-17 19:56:39 -0500805 return;
James Smart13815c82008-01-11 01:52:48 -0500806 } else {
807 /*
808 * If heart beat timeout called with hb_outstanding set
809 * we need to take the HBA offline.
810 */
811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
812 "0459 Adapter heartbeat failure, "
813 "taking this port offline.\n");
814
815 spin_lock_irq(&phba->hbalock);
816 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
817 spin_unlock_irq(&phba->hbalock);
818
819 lpfc_offline_prep(phba);
820 lpfc_offline(phba);
821 lpfc_unblock_mgmt_io(phba);
822 phba->link_state = LPFC_HBA_ERROR;
823 lpfc_hba_down_post(phba);
James Smart858c9f62007-06-17 19:56:39 -0500824 }
James Smart858c9f62007-06-17 19:56:39 -0500825 }
826}
827
James Smarte59058c2008-08-24 21:49:00 -0400828/**
James Smart3621a712009-04-06 18:47:14 -0400829 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -0400830 * @phba: pointer to lpfc hba data structure.
831 *
832 * This routine is called to bring the HBA offline when HBA hardware error
833 * other than Port Error 6 has been detected.
834 **/
James Smart09372822008-01-11 01:52:54 -0500835static void
836lpfc_offline_eratt(struct lpfc_hba *phba)
837{
838 struct lpfc_sli *psli = &phba->sli;
839
840 spin_lock_irq(&phba->hbalock);
841 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
842 spin_unlock_irq(&phba->hbalock);
843 lpfc_offline_prep(phba);
844
845 lpfc_offline(phba);
846 lpfc_reset_barrier(phba);
847 lpfc_sli_brdreset(phba);
848 lpfc_hba_down_post(phba);
849 lpfc_sli_brdready(phba, HS_MBRDY);
850 lpfc_unblock_mgmt_io(phba);
851 phba->link_state = LPFC_HBA_ERROR;
852 return;
853}
854
James Smarte59058c2008-08-24 21:49:00 -0400855/**
James Smarta257bf92009-04-06 18:48:10 -0400856 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
857 * @phba: pointer to lpfc hba data structure.
858 *
859 * This routine is invoked to handle the deferred HBA hardware error
860 * conditions. This type of error is indicated by HBA by setting ER1
861 * and another ER bit in the host status register. The driver will
862 * wait until the ER1 bit clears before handling the error condition.
863 **/
864static void
865lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
866{
867 uint32_t old_host_status = phba->work_hs;
868 struct lpfc_sli_ring *pring;
869 struct lpfc_sli *psli = &phba->sli;
870
871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
872 "0479 Deferred Adapter Hardware Error "
873 "Data: x%x x%x x%x\n",
874 phba->work_hs,
875 phba->work_status[0], phba->work_status[1]);
876
877 spin_lock_irq(&phba->hbalock);
878 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
879 spin_unlock_irq(&phba->hbalock);
880
881
882 /*
883 * Firmware stops when it triggred erratt. That could cause the I/Os
884 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
885 * SCSI layer retry it after re-establishing link.
886 */
887 pring = &psli->ring[psli->fcp_ring];
888 lpfc_sli_abort_iocb_ring(phba, pring);
889
890 /*
891 * There was a firmware error. Take the hba offline and then
892 * attempt to restart it.
893 */
894 lpfc_offline_prep(phba);
895 lpfc_offline(phba);
896
897 /* Wait for the ER1 bit to clear.*/
898 while (phba->work_hs & HS_FFER1) {
899 msleep(100);
900 phba->work_hs = readl(phba->HSregaddr);
901 /* If driver is unloading let the worker thread continue */
902 if (phba->pport->load_flag & FC_UNLOADING) {
903 phba->work_hs = 0;
904 break;
905 }
906 }
907
908 /*
909 * This is to ptrotect against a race condition in which
910 * first write to the host attention register clear the
911 * host status register.
912 */
913 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
914 phba->work_hs = old_host_status & ~HS_FFER1;
915
James Smart3772a992009-05-22 14:50:54 -0400916 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -0400917 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -0400918 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -0400919 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
920 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
921}
922
James Smart3772a992009-05-22 14:50:54 -0400923static void
924lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
925{
926 struct lpfc_board_event_header board_event;
927 struct Scsi_Host *shost;
928
929 board_event.event_type = FC_REG_BOARD_EVENT;
930 board_event.subcategory = LPFC_EVENT_PORTINTERR;
931 shost = lpfc_shost_from_vport(phba->pport);
932 fc_host_post_vendor_event(shost, fc_get_event_number(),
933 sizeof(board_event),
934 (char *) &board_event,
935 LPFC_NL_VENDOR_ID);
936}
937
James Smarta257bf92009-04-06 18:48:10 -0400938/**
James Smart3772a992009-05-22 14:50:54 -0400939 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -0400940 * @phba: pointer to lpfc hba data structure.
941 *
942 * This routine is invoked to handle the following HBA hardware error
943 * conditions:
944 * 1 - HBA error attention interrupt
945 * 2 - DMA ring index out of range
946 * 3 - Mailbox command came back as unknown
947 **/
James Smart3772a992009-05-22 14:50:54 -0400948static void
949lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500950{
James Smart2e0fef82007-06-17 19:56:36 -0500951 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -0500952 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -0500953 struct lpfc_sli_ring *pring;
James Smartd2873e42006-08-18 17:46:43 -0400954 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -0400955 unsigned long temperature;
956 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -0500957 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -0500958
Linas Vepstas8d63f372007-02-14 14:28:36 -0600959 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -0400960 * since we cannot communicate with the pci card anyway.
961 */
962 if (pci_channel_offline(phba->pcidev)) {
963 spin_lock_irq(&phba->hbalock);
964 phba->hba_flag &= ~DEFER_ERATT;
965 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -0600966 return;
James Smart3772a992009-05-22 14:50:54 -0400967 }
968
James Smart13815c82008-01-11 01:52:48 -0500969 /* If resets are disabled then leave the HBA alone and return */
970 if (!phba->cfg_enable_hba_reset)
971 return;
dea31012005-04-17 16:05:31 -0500972
James Smartea2151b2008-09-07 11:52:10 -0400973 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -0400974 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -0400975
James Smarta257bf92009-04-06 18:48:10 -0400976 if (phba->hba_flag & DEFER_ERATT)
977 lpfc_handle_deferred_eratt(phba);
978
James Smart97eab632008-04-07 10:16:05 -0400979 if (phba->work_hs & HS_FFER6) {
dea31012005-04-17 16:05:31 -0500980 /* Re-establishing Link */
981 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400982 "1301 Re-establishing Link "
dea31012005-04-17 16:05:31 -0500983 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400984 phba->work_hs,
dea31012005-04-17 16:05:31 -0500985 phba->work_status[0], phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -0400986
James Smart92d7f7b2007-06-17 19:56:38 -0500987 spin_lock_irq(&phba->hbalock);
James Smart92908312006-03-07 15:04:13 -0500988 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -0500989 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500990
991 /*
992 * Firmware stops when it triggled erratt with HS_FFER6.
993 * That could cause the I/Os dropped by the firmware.
994 * Error iocb (I/O) on txcmplq and let the SCSI layer
995 * retry it after re-establishing link.
996 */
997 pring = &psli->ring[psli->fcp_ring];
998 lpfc_sli_abort_iocb_ring(phba, pring);
999
dea31012005-04-17 16:05:31 -05001000 /*
1001 * There was a firmware error. Take the hba offline and then
1002 * attempt to restart it.
1003 */
James Smart46fa3112007-04-25 09:51:45 -04001004 lpfc_offline_prep(phba);
dea31012005-04-17 16:05:31 -05001005 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001006 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001007 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001008 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001009 return;
1010 }
James Smart46fa3112007-04-25 09:51:45 -04001011 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001012 } else if (phba->work_hs & HS_CRIT_TEMP) {
1013 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1014 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1015 temp_event_data.event_code = LPFC_CRIT_TEMP;
1016 temp_event_data.data = (uint32_t)temperature;
1017
1018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001019 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001020 "(%ld), taking this port offline "
1021 "Data: x%x x%x x%x\n",
1022 temperature, phba->work_hs,
1023 phba->work_status[0], phba->work_status[1]);
1024
1025 shost = lpfc_shost_from_vport(phba->pport);
1026 fc_host_post_vendor_event(shost, fc_get_event_number(),
1027 sizeof(temp_event_data),
1028 (char *) &temp_event_data,
1029 SCSI_NL_VID_TYPE_PCI
1030 | PCI_VENDOR_ID_EMULEX);
1031
James Smart7af67052007-10-27 13:38:11 -04001032 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001033 phba->over_temp_state = HBA_OVER_TEMP;
1034 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001035 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001036
dea31012005-04-17 16:05:31 -05001037 } else {
1038 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001039 * failure is a value other than FFER6. Do not call the offline
1040 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001041 */
1042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001043 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001044 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001045 phba->work_hs,
dea31012005-04-17 16:05:31 -05001046 phba->work_status[0], phba->work_status[1]);
1047
James Smartd2873e42006-08-18 17:46:43 -04001048 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001049 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001050 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001051 sizeof(event_data), (char *) &event_data,
1052 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1053
James Smart09372822008-01-11 01:52:54 -05001054 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001055 }
James Smart93996272008-08-24 21:50:30 -04001056 return;
dea31012005-04-17 16:05:31 -05001057}
1058
James Smarte59058c2008-08-24 21:49:00 -04001059/**
James Smart3621a712009-04-06 18:47:14 -04001060 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001061 * @phba: pointer to lpfc hba data structure.
1062 *
1063 * This routine is invoked from the worker thread to handle a HBA host
1064 * attention link event.
1065 **/
dea31012005-04-17 16:05:31 -05001066void
James Smart2e0fef82007-06-17 19:56:36 -05001067lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001068{
James Smart2e0fef82007-06-17 19:56:36 -05001069 struct lpfc_vport *vport = phba->pport;
1070 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001071 LPFC_MBOXQ_t *pmb;
1072 volatile uint32_t control;
1073 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001074 int rc = 0;
dea31012005-04-17 16:05:31 -05001075
1076 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001077 if (!pmb) {
1078 rc = 1;
dea31012005-04-17 16:05:31 -05001079 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001080 }
dea31012005-04-17 16:05:31 -05001081
1082 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001083 if (!mp) {
1084 rc = 2;
dea31012005-04-17 16:05:31 -05001085 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001086 }
dea31012005-04-17 16:05:31 -05001087
1088 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001089 if (!mp->virt) {
1090 rc = 3;
dea31012005-04-17 16:05:31 -05001091 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001092 }
dea31012005-04-17 16:05:31 -05001093
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001094 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001095 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001096
1097 psli->slistat.link_event++;
1098 lpfc_read_la(phba, pmb, mp);
1099 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
James Smart2e0fef82007-06-17 19:56:36 -05001100 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001101 /* Block ELS IOCBs until we have processed this mbox command */
1102 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001103 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001104 if (rc == MBX_NOT_FINISHED) {
1105 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001106 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001107 }
dea31012005-04-17 16:05:31 -05001108
1109 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001110 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001111 writel(HA_LATT, phba->HAregaddr);
1112 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001113 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001114
1115 return;
1116
James Smart14691152006-12-02 13:34:28 -05001117lpfc_handle_latt_free_mbuf:
James Smart0d2b6b82008-06-14 22:52:47 -04001118 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001119 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001120lpfc_handle_latt_free_mp:
1121 kfree(mp);
1122lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001123 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001124lpfc_handle_latt_err_exit:
1125 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001126 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001127 psli->sli_flag |= LPFC_PROCESS_LA;
1128 control = readl(phba->HCregaddr);
1129 control |= HC_LAINT_ENA;
1130 writel(control, phba->HCregaddr);
1131 readl(phba->HCregaddr); /* flush */
1132
1133 /* Clear Link Attention in HA REG */
1134 writel(HA_LATT, phba->HAregaddr);
1135 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001137 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001138 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001139
James Smart09372822008-01-11 01:52:54 -05001140 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1141 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001142
1143 return;
1144}
1145
James Smarte59058c2008-08-24 21:49:00 -04001146/**
James Smart3621a712009-04-06 18:47:14 -04001147 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001148 * @phba: pointer to lpfc hba data structure.
1149 * @vpd: pointer to the vital product data.
1150 * @len: length of the vital product data in bytes.
1151 *
1152 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1153 * an array of characters. In this routine, the ModelName, ProgramType, and
1154 * ModelDesc, etc. fields of the phba data structure will be populated.
1155 *
1156 * Return codes
1157 * 0 - pointer to the VPD passed in is NULL
1158 * 1 - success
1159 **/
James Smart3772a992009-05-22 14:50:54 -04001160int
James Smart2e0fef82007-06-17 19:56:36 -05001161lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001162{
1163 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001164 int Length;
dea31012005-04-17 16:05:31 -05001165 int i, j;
1166 int finished = 0;
1167 int index = 0;
1168
1169 if (!vpd)
1170 return 0;
1171
1172 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001173 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001174 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001175 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1176 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001177 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001178 switch (vpd[index]) {
1179 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001180 case 0x91:
dea31012005-04-17 16:05:31 -05001181 index += 1;
1182 lenlo = vpd[index];
1183 index += 1;
1184 lenhi = vpd[index];
1185 index += 1;
1186 i = ((((unsigned short)lenhi) << 8) + lenlo);
1187 index += i;
1188 break;
1189 case 0x90:
1190 index += 1;
1191 lenlo = vpd[index];
1192 index += 1;
1193 lenhi = vpd[index];
1194 index += 1;
1195 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001196 if (Length > len - index)
1197 Length = len - index;
dea31012005-04-17 16:05:31 -05001198 while (Length > 0) {
1199 /* Look for Serial Number */
1200 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1201 index += 2;
1202 i = vpd[index];
1203 index += 1;
1204 j = 0;
1205 Length -= (3+i);
1206 while(i--) {
1207 phba->SerialNumber[j++] = vpd[index++];
1208 if (j == 31)
1209 break;
1210 }
1211 phba->SerialNumber[j] = 0;
1212 continue;
1213 }
1214 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1215 phba->vpd_flag |= VPD_MODEL_DESC;
1216 index += 2;
1217 i = vpd[index];
1218 index += 1;
1219 j = 0;
1220 Length -= (3+i);
1221 while(i--) {
1222 phba->ModelDesc[j++] = vpd[index++];
1223 if (j == 255)
1224 break;
1225 }
1226 phba->ModelDesc[j] = 0;
1227 continue;
1228 }
1229 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1230 phba->vpd_flag |= VPD_MODEL_NAME;
1231 index += 2;
1232 i = vpd[index];
1233 index += 1;
1234 j = 0;
1235 Length -= (3+i);
1236 while(i--) {
1237 phba->ModelName[j++] = vpd[index++];
1238 if (j == 79)
1239 break;
1240 }
1241 phba->ModelName[j] = 0;
1242 continue;
1243 }
1244 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1245 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1246 index += 2;
1247 i = vpd[index];
1248 index += 1;
1249 j = 0;
1250 Length -= (3+i);
1251 while(i--) {
1252 phba->ProgramType[j++] = vpd[index++];
1253 if (j == 255)
1254 break;
1255 }
1256 phba->ProgramType[j] = 0;
1257 continue;
1258 }
1259 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1260 phba->vpd_flag |= VPD_PORT;
1261 index += 2;
1262 i = vpd[index];
1263 index += 1;
1264 j = 0;
1265 Length -= (3+i);
1266 while(i--) {
1267 phba->Port[j++] = vpd[index++];
1268 if (j == 19)
1269 break;
1270 }
1271 phba->Port[j] = 0;
1272 continue;
1273 }
1274 else {
1275 index += 2;
1276 i = vpd[index];
1277 index += 1;
1278 index += i;
1279 Length -= (3 + i);
1280 }
1281 }
1282 finished = 0;
1283 break;
1284 case 0x78:
1285 finished = 1;
1286 break;
1287 default:
1288 index ++;
1289 break;
1290 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001291 }
dea31012005-04-17 16:05:31 -05001292
1293 return(1);
1294}
1295
James Smarte59058c2008-08-24 21:49:00 -04001296/**
James Smart3621a712009-04-06 18:47:14 -04001297 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04001298 * @phba: pointer to lpfc hba data structure.
1299 * @mdp: pointer to the data structure to hold the derived model name.
1300 * @descp: pointer to the data structure to hold the derived description.
1301 *
1302 * This routine retrieves HBA's description based on its registered PCI device
1303 * ID. The @descp passed into this function points to an array of 256 chars. It
1304 * shall be returned with the model name, maximum speed, and the host bus type.
1305 * The @mdp passed into this function points to an array of 80 chars. When the
1306 * function returns, the @mdp will be filled with the model name.
1307 **/
dea31012005-04-17 16:05:31 -05001308static void
James Smart2e0fef82007-06-17 19:56:36 -05001309lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05001310{
1311 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05001312 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001313 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04001314 int GE = 0;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001315 struct {
1316 char * name;
1317 int max_speed;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001318 char * bus;
James Smart18a3b592006-12-02 13:35:08 -05001319 } m = {"<Unknown>", 0, ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001320
1321 if (mdp && mdp[0] != '\0'
1322 && descp && descp[0] != '\0')
1323 return;
1324
1325 if (phba->lmt & LMT_10Gb)
1326 max_speed = 10;
1327 else if (phba->lmt & LMT_8Gb)
1328 max_speed = 8;
1329 else if (phba->lmt & LMT_4Gb)
1330 max_speed = 4;
1331 else if (phba->lmt & LMT_2Gb)
1332 max_speed = 2;
1333 else
1334 max_speed = 1;
dea31012005-04-17 16:05:31 -05001335
1336 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05001337
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001338 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001339 case PCI_DEVICE_ID_FIREFLY:
James Smart18a3b592006-12-02 13:35:08 -05001340 m = (typeof(m)){"LP6000", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001341 break;
dea31012005-04-17 16:05:31 -05001342 case PCI_DEVICE_ID_SUPERFLY:
1343 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart18a3b592006-12-02 13:35:08 -05001344 m = (typeof(m)){"LP7000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001345 else
James Smart18a3b592006-12-02 13:35:08 -05001346 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001347 break;
1348 case PCI_DEVICE_ID_DRAGONFLY:
James Smart18a3b592006-12-02 13:35:08 -05001349 m = (typeof(m)){"LP8000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001350 break;
1351 case PCI_DEVICE_ID_CENTAUR:
1352 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart18a3b592006-12-02 13:35:08 -05001353 m = (typeof(m)){"LP9002", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001354 else
James Smart18a3b592006-12-02 13:35:08 -05001355 m = (typeof(m)){"LP9000", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001356 break;
1357 case PCI_DEVICE_ID_RFLY:
James Smart18a3b592006-12-02 13:35:08 -05001358 m = (typeof(m)){"LP952", max_speed, "PCI"};
dea31012005-04-17 16:05:31 -05001359 break;
1360 case PCI_DEVICE_ID_PEGASUS:
James Smart18a3b592006-12-02 13:35:08 -05001361 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001362 break;
1363 case PCI_DEVICE_ID_THOR:
James Smart18a3b592006-12-02 13:35:08 -05001364 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001365 break;
1366 case PCI_DEVICE_ID_VIPER:
James Smart18a3b592006-12-02 13:35:08 -05001367 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001368 break;
1369 case PCI_DEVICE_ID_PFLY:
James Smart18a3b592006-12-02 13:35:08 -05001370 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001371 break;
1372 case PCI_DEVICE_ID_TFLY:
James Smart18a3b592006-12-02 13:35:08 -05001373 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001374 break;
1375 case PCI_DEVICE_ID_HELIOS:
James Smart18a3b592006-12-02 13:35:08 -05001376 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001377 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001378 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001379 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001380 break;
1381 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001382 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001383 break;
1384 case PCI_DEVICE_ID_NEPTUNE:
James Smart18a3b592006-12-02 13:35:08 -05001385 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001386 break;
1387 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001388 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001389 break;
1390 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart18a3b592006-12-02 13:35:08 -05001391 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001392 break;
dea31012005-04-17 16:05:31 -05001393 case PCI_DEVICE_ID_BMID:
James Smart18a3b592006-12-02 13:35:08 -05001394 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001395 break;
1396 case PCI_DEVICE_ID_BSMB:
James Smart18a3b592006-12-02 13:35:08 -05001397 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
dea31012005-04-17 16:05:31 -05001398 break;
1399 case PCI_DEVICE_ID_ZEPHYR:
James Smart18a3b592006-12-02 13:35:08 -05001400 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001401 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001402 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smart18a3b592006-12-02 13:35:08 -05001403 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001404 break;
1405 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta257bf92009-04-06 18:48:10 -04001406 m = (typeof(m)){"LP2105", max_speed, "PCIe"};
1407 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001408 break;
dea31012005-04-17 16:05:31 -05001409 case PCI_DEVICE_ID_ZMID:
James Smart18a3b592006-12-02 13:35:08 -05001410 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001411 break;
1412 case PCI_DEVICE_ID_ZSMB:
James Smart18a3b592006-12-02 13:35:08 -05001413 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
dea31012005-04-17 16:05:31 -05001414 break;
1415 case PCI_DEVICE_ID_LP101:
James Smart18a3b592006-12-02 13:35:08 -05001416 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
dea31012005-04-17 16:05:31 -05001417 break;
1418 case PCI_DEVICE_ID_LP10000S:
James Smart18a3b592006-12-02 13:35:08 -05001419 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04001420 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001421 case PCI_DEVICE_ID_LP11000S:
James Smart18a3b592006-12-02 13:35:08 -05001422 m = (typeof(m)){"LP11000-S", max_speed,
1423 "PCI-X2"};
1424 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001425 case PCI_DEVICE_ID_LPE11000S:
James Smart18a3b592006-12-02 13:35:08 -05001426 m = (typeof(m)){"LPe11000-S", max_speed,
1427 "PCIe"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001428 break;
James Smartb87eab32007-04-25 09:53:28 -04001429 case PCI_DEVICE_ID_SAT:
1430 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1431 break;
1432 case PCI_DEVICE_ID_SAT_MID:
1433 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1434 break;
1435 case PCI_DEVICE_ID_SAT_SMB:
1436 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1437 break;
1438 case PCI_DEVICE_ID_SAT_DCSP:
1439 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1440 break;
1441 case PCI_DEVICE_ID_SAT_SCSP:
1442 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1443 break;
1444 case PCI_DEVICE_ID_SAT_S:
1445 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1446 break;
James Smart84774a42008-08-24 21:50:06 -04001447 case PCI_DEVICE_ID_HORNET:
1448 m = (typeof(m)){"LP21000", max_speed, "PCIe"};
1449 GE = 1;
1450 break;
1451 case PCI_DEVICE_ID_PROTEUS_VF:
1452 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1453 break;
1454 case PCI_DEVICE_ID_PROTEUS_PF:
1455 m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"};
1456 break;
1457 case PCI_DEVICE_ID_PROTEUS_S:
1458 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1459 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05001460 default:
Randy Dunlap041976f2006-06-25 01:58:51 -07001461 m = (typeof(m)){ NULL };
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05001462 break;
dea31012005-04-17 16:05:31 -05001463 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001464
1465 if (mdp && mdp[0] == '\0')
1466 snprintf(mdp, 79,"%s", m.name);
1467 if (descp && descp[0] == '\0')
1468 snprintf(descp, 255,
James Smart84774a42008-08-24 21:50:06 -04001469 "Emulex %s %d%s %s %s",
1470 m.name, m.max_speed,
1471 (GE) ? "GE" : "Gb",
1472 m.bus,
1473 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter");
dea31012005-04-17 16:05:31 -05001474}
1475
James Smarte59058c2008-08-24 21:49:00 -04001476/**
James Smart3621a712009-04-06 18:47:14 -04001477 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001478 * @phba: pointer to lpfc hba data structure.
1479 * @pring: pointer to a IOCB ring.
1480 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1481 *
1482 * This routine posts a given number of IOCBs with the associated DMA buffer
1483 * descriptors specified by the cnt argument to the given IOCB ring.
1484 *
1485 * Return codes
1486 * The number of IOCBs NOT able to be posted to the IOCB ring.
1487 **/
dea31012005-04-17 16:05:31 -05001488int
James Smart495a7142008-06-14 22:52:59 -04001489lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05001490{
1491 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001492 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05001493 struct lpfc_dmabuf *mp1, *mp2;
1494
1495 cnt += pring->missbufcnt;
1496
1497 /* While there are buffers to post */
1498 while (cnt > 0) {
1499 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04001500 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05001501 if (iocb == NULL) {
1502 pring->missbufcnt = cnt;
1503 return cnt;
1504 }
dea31012005-04-17 16:05:31 -05001505 icmd = &iocb->iocb;
1506
1507 /* 2 buffers can be posted per command */
1508 /* Allocate buffer to post */
1509 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1510 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04001511 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1512 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001513 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001514 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001515 pring->missbufcnt = cnt;
1516 return cnt;
1517 }
1518
1519 INIT_LIST_HEAD(&mp1->list);
1520 /* Allocate buffer to post */
1521 if (cnt > 1) {
1522 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1523 if (mp2)
1524 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1525 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04001526 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001527 kfree(mp2);
dea31012005-04-17 16:05:31 -05001528 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1529 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05001530 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001531 pring->missbufcnt = cnt;
1532 return cnt;
1533 }
1534
1535 INIT_LIST_HEAD(&mp2->list);
1536 } else {
1537 mp2 = NULL;
1538 }
1539
1540 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1541 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1542 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1543 icmd->ulpBdeCount = 1;
1544 cnt--;
1545 if (mp2) {
1546 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1547 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1548 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1549 cnt--;
1550 icmd->ulpBdeCount = 2;
1551 }
1552
1553 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1554 icmd->ulpLe = 1;
1555
James Smart3772a992009-05-22 14:50:54 -04001556 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
1557 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001558 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1559 kfree(mp1);
1560 cnt++;
1561 if (mp2) {
1562 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1563 kfree(mp2);
1564 cnt++;
1565 }
James Bottomley604a3e32005-10-29 10:28:33 -05001566 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05001567 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05001568 return cnt;
1569 }
dea31012005-04-17 16:05:31 -05001570 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05001571 if (mp2)
dea31012005-04-17 16:05:31 -05001572 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05001573 }
1574 pring->missbufcnt = 0;
1575 return 0;
1576}
1577
James Smarte59058c2008-08-24 21:49:00 -04001578/**
James Smart3621a712009-04-06 18:47:14 -04001579 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04001580 * @phba: pointer to lpfc hba data structure.
1581 *
1582 * This routine posts initial receive IOCB buffers to the ELS ring. The
1583 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1584 * set to 64 IOCBs.
1585 *
1586 * Return codes
1587 * 0 - success (currently always success)
1588 **/
dea31012005-04-17 16:05:31 -05001589static int
James Smart2e0fef82007-06-17 19:56:36 -05001590lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001591{
1592 struct lpfc_sli *psli = &phba->sli;
1593
1594 /* Ring 0, ELS / CT buffers */
James Smart495a7142008-06-14 22:52:59 -04001595 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05001596 /* Ring 2 - FCP no buffers needed */
1597
1598 return 0;
1599}
1600
1601#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1602
James Smarte59058c2008-08-24 21:49:00 -04001603/**
James Smart3621a712009-04-06 18:47:14 -04001604 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04001605 * @HashResultPointer: pointer to an array as hash table.
1606 *
1607 * This routine sets up the initial values to the array of hash table entries
1608 * for the LC HBAs.
1609 **/
dea31012005-04-17 16:05:31 -05001610static void
1611lpfc_sha_init(uint32_t * HashResultPointer)
1612{
1613 HashResultPointer[0] = 0x67452301;
1614 HashResultPointer[1] = 0xEFCDAB89;
1615 HashResultPointer[2] = 0x98BADCFE;
1616 HashResultPointer[3] = 0x10325476;
1617 HashResultPointer[4] = 0xC3D2E1F0;
1618}
1619
James Smarte59058c2008-08-24 21:49:00 -04001620/**
James Smart3621a712009-04-06 18:47:14 -04001621 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04001622 * @HashResultPointer: pointer to an initial/result hash table.
1623 * @HashWorkingPointer: pointer to an working hash table.
1624 *
1625 * This routine iterates an initial hash table pointed by @HashResultPointer
1626 * with the values from the working hash table pointeed by @HashWorkingPointer.
1627 * The results are putting back to the initial hash table, returned through
1628 * the @HashResultPointer as the result hash table.
1629 **/
dea31012005-04-17 16:05:31 -05001630static void
1631lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1632{
1633 int t;
1634 uint32_t TEMP;
1635 uint32_t A, B, C, D, E;
1636 t = 16;
1637 do {
1638 HashWorkingPointer[t] =
1639 S(1,
1640 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1641 8] ^
1642 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1643 } while (++t <= 79);
1644 t = 0;
1645 A = HashResultPointer[0];
1646 B = HashResultPointer[1];
1647 C = HashResultPointer[2];
1648 D = HashResultPointer[3];
1649 E = HashResultPointer[4];
1650
1651 do {
1652 if (t < 20) {
1653 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1654 } else if (t < 40) {
1655 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1656 } else if (t < 60) {
1657 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1658 } else {
1659 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1660 }
1661 TEMP += S(5, A) + E + HashWorkingPointer[t];
1662 E = D;
1663 D = C;
1664 C = S(30, B);
1665 B = A;
1666 A = TEMP;
1667 } while (++t <= 79);
1668
1669 HashResultPointer[0] += A;
1670 HashResultPointer[1] += B;
1671 HashResultPointer[2] += C;
1672 HashResultPointer[3] += D;
1673 HashResultPointer[4] += E;
1674
1675}
1676
James Smarte59058c2008-08-24 21:49:00 -04001677/**
James Smart3621a712009-04-06 18:47:14 -04001678 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04001679 * @RandomChallenge: pointer to the entry of host challenge random number array.
1680 * @HashWorking: pointer to the entry of the working hash array.
1681 *
1682 * This routine calculates the working hash array referred by @HashWorking
1683 * from the challenge random numbers associated with the host, referred by
1684 * @RandomChallenge. The result is put into the entry of the working hash
1685 * array and returned by reference through @HashWorking.
1686 **/
dea31012005-04-17 16:05:31 -05001687static void
1688lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1689{
1690 *HashWorking = (*RandomChallenge ^ *HashWorking);
1691}
1692
James Smarte59058c2008-08-24 21:49:00 -04001693/**
James Smart3621a712009-04-06 18:47:14 -04001694 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04001695 * @phba: pointer to lpfc hba data structure.
1696 * @hbainit: pointer to an array of unsigned 32-bit integers.
1697 *
1698 * This routine performs the special handling for LC HBA initialization.
1699 **/
dea31012005-04-17 16:05:31 -05001700void
1701lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1702{
1703 int t;
1704 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05001705 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05001706
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001707 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001708 if (!HashWorking)
1709 return;
1710
dea31012005-04-17 16:05:31 -05001711 HashWorking[0] = HashWorking[78] = *pwwnn++;
1712 HashWorking[1] = HashWorking[79] = *pwwnn;
1713
1714 for (t = 0; t < 7; t++)
1715 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1716
1717 lpfc_sha_init(hbainit);
1718 lpfc_sha_iterate(hbainit, HashWorking);
1719 kfree(HashWorking);
1720}
1721
James Smarte59058c2008-08-24 21:49:00 -04001722/**
James Smart3621a712009-04-06 18:47:14 -04001723 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04001724 * @vport: pointer to a virtual N_Port data structure.
1725 *
1726 * This routine performs the necessary cleanups before deleting the @vport.
1727 * It invokes the discovery state machine to perform necessary state
1728 * transitions and to release the ndlps associated with the @vport. Note,
1729 * the physical port is treated as @vport 0.
1730 **/
James Smart87af33f2007-10-27 13:37:43 -04001731void
James Smart2e0fef82007-06-17 19:56:36 -05001732lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001733{
James Smart87af33f2007-10-27 13:37:43 -04001734 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001735 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04001736 int i = 0;
dea31012005-04-17 16:05:31 -05001737
James Smart87af33f2007-10-27 13:37:43 -04001738 if (phba->link_state > LPFC_LINK_DOWN)
1739 lpfc_port_link_failure(vport);
1740
1741 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001742 if (!NLP_CHK_NODE_ACT(ndlp)) {
1743 ndlp = lpfc_enable_node(vport, ndlp,
1744 NLP_STE_UNUSED_NODE);
1745 if (!ndlp)
1746 continue;
1747 spin_lock_irq(&phba->ndlp_lock);
1748 NLP_SET_FREE_REQ(ndlp);
1749 spin_unlock_irq(&phba->ndlp_lock);
1750 /* Trigger the release of the ndlp memory */
1751 lpfc_nlp_put(ndlp);
1752 continue;
1753 }
1754 spin_lock_irq(&phba->ndlp_lock);
1755 if (NLP_CHK_FREE_REQ(ndlp)) {
1756 /* The ndlp should not be in memory free mode already */
1757 spin_unlock_irq(&phba->ndlp_lock);
1758 continue;
1759 } else
1760 /* Indicate request for freeing ndlp memory */
1761 NLP_SET_FREE_REQ(ndlp);
1762 spin_unlock_irq(&phba->ndlp_lock);
1763
James Smart58da1ff2008-04-07 10:15:56 -04001764 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1765 ndlp->nlp_DID == Fabric_DID) {
1766 /* Just free up ndlp with Fabric_DID for vports */
1767 lpfc_nlp_put(ndlp);
1768 continue;
1769 }
1770
James Smart87af33f2007-10-27 13:37:43 -04001771 if (ndlp->nlp_type & NLP_FABRIC)
1772 lpfc_disc_state_machine(vport, ndlp, NULL,
1773 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05001774
James Smart87af33f2007-10-27 13:37:43 -04001775 lpfc_disc_state_machine(vport, ndlp, NULL,
1776 NLP_EVT_DEVICE_RM);
James Smart495a7142008-06-14 22:52:59 -04001777
James Smart87af33f2007-10-27 13:37:43 -04001778 }
1779
James Smarta8adb832007-10-27 13:37:53 -04001780 /* At this point, ALL ndlp's should be gone
1781 * because of the previous NLP_EVT_DEVICE_RM.
1782 * Lets wait for this to happen, if needed.
1783 */
James Smart87af33f2007-10-27 13:37:43 -04001784 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04001785 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04001786 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04001787 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05001788 list_for_each_entry_safe(ndlp, next_ndlp,
1789 &vport->fc_nodes, nlp_listp) {
1790 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1791 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04001792 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05001793 "usgmap:x%x refcnt:%d\n",
1794 ndlp->nlp_DID, (void *)ndlp,
1795 ndlp->nlp_usg_map,
1796 atomic_read(
1797 &ndlp->kref.refcount));
1798 }
James Smarta8adb832007-10-27 13:37:53 -04001799 break;
James Smart87af33f2007-10-27 13:37:43 -04001800 }
James Smarta8adb832007-10-27 13:37:53 -04001801
1802 /* Wait for any activity on ndlps to settle */
1803 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04001804 }
dea31012005-04-17 16:05:31 -05001805}
1806
James Smarte59058c2008-08-24 21:49:00 -04001807/**
James Smart3621a712009-04-06 18:47:14 -04001808 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04001809 * @vport: pointer to a virtual N_Port data structure.
1810 *
1811 * This routine stops all the timers associated with a @vport. This function
1812 * is invoked before disabling or deleting a @vport. Note that the physical
1813 * port is treated as @vport 0.
1814 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001815void
1816lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001817{
James Smart92d7f7b2007-06-17 19:56:38 -05001818 del_timer_sync(&vport->els_tmofunc);
1819 del_timer_sync(&vport->fc_fdmitmo);
1820 lpfc_can_disctmo(vport);
1821 return;
dea31012005-04-17 16:05:31 -05001822}
1823
James Smarte59058c2008-08-24 21:49:00 -04001824/**
James Smart3772a992009-05-22 14:50:54 -04001825 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04001826 * @phba: pointer to lpfc hba data structure.
1827 *
1828 * This routine stops all the timers associated with a HBA. This function is
1829 * invoked before either putting a HBA offline or unloading the driver.
1830 **/
James Smart3772a992009-05-22 14:50:54 -04001831void
1832lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001833{
James Smart51ef4c22007-08-02 11:10:31 -04001834 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05001835 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05001836 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04001837 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04001838 del_timer_sync(&phba->hb_tmofunc);
1839 phba->hb_outstanding = 0;
1840
1841 switch (phba->pci_dev_grp) {
1842 case LPFC_PCI_DEV_LP:
1843 /* Stop any LightPulse device specific driver timers */
1844 del_timer_sync(&phba->fcp_poll_timer);
1845 break;
1846 case LPFC_PCI_DEV_OC:
1847 /* Stop any OneConnect device sepcific driver timers */
1848 break;
1849 default:
1850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1851 "0297 Invalid device group (x%x)\n",
1852 phba->pci_dev_grp);
1853 break;
1854 }
James Smart2e0fef82007-06-17 19:56:36 -05001855 return;
dea31012005-04-17 16:05:31 -05001856}
1857
James Smarte59058c2008-08-24 21:49:00 -04001858/**
James Smart3621a712009-04-06 18:47:14 -04001859 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04001860 * @phba: pointer to lpfc hba data structure.
1861 *
1862 * This routine marks a HBA's management interface as blocked. Once the HBA's
1863 * management interface is marked as blocked, all the user space access to
1864 * the HBA, whether they are from sysfs interface or libdfc interface will
1865 * all be blocked. The HBA is set to block the management interface when the
1866 * driver prepares the HBA interface for online or offline.
1867 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001868static void
1869lpfc_block_mgmt_io(struct lpfc_hba * phba)
1870{
1871 unsigned long iflag;
1872
1873 spin_lock_irqsave(&phba->hbalock, iflag);
1874 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1875 spin_unlock_irqrestore(&phba->hbalock, iflag);
1876}
1877
James Smarte59058c2008-08-24 21:49:00 -04001878/**
James Smart3621a712009-04-06 18:47:14 -04001879 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04001880 * @phba: pointer to lpfc hba data structure.
1881 *
1882 * This routine initializes the HBA and brings a HBA online. During this
1883 * process, the management interface is blocked to prevent user space access
1884 * to the HBA interfering with the driver initialization.
1885 *
1886 * Return codes
1887 * 0 - successful
1888 * 1 - failed
1889 **/
dea31012005-04-17 16:05:31 -05001890int
James Smart2e0fef82007-06-17 19:56:36 -05001891lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001892{
Julia Lawall372bd282008-12-16 16:15:08 +01001893 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04001894 struct lpfc_vport **vports;
1895 int i;
James Smart2e0fef82007-06-17 19:56:36 -05001896
dea31012005-04-17 16:05:31 -05001897 if (!phba)
1898 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01001899 vport = phba->pport;
dea31012005-04-17 16:05:31 -05001900
James Smart2e0fef82007-06-17 19:56:36 -05001901 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05001902 return 0;
1903
James Smarted957682007-06-17 19:56:37 -05001904 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001905 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05001906
James Smart46fa3112007-04-25 09:51:45 -04001907 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001908
James Smart46fa3112007-04-25 09:51:45 -04001909 if (!lpfc_sli_queue_setup(phba)) {
1910 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001911 return 1;
James Smart46fa3112007-04-25 09:51:45 -04001912 }
1913
1914 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1915 lpfc_unblock_mgmt_io(phba);
1916 return 1;
1917 }
dea31012005-04-17 16:05:31 -05001918
James Smart549e55c2007-08-02 11:09:51 -04001919 vports = lpfc_create_vport_work_array(phba);
1920 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05001921 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001922 struct Scsi_Host *shost;
1923 shost = lpfc_shost_from_vport(vports[i]);
1924 spin_lock_irq(shost->host_lock);
1925 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1926 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1927 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1928 spin_unlock_irq(shost->host_lock);
1929 }
James Smart09372822008-01-11 01:52:54 -05001930 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001931
James Smart46fa3112007-04-25 09:51:45 -04001932 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001933 return 0;
1934}
1935
James Smarte59058c2008-08-24 21:49:00 -04001936/**
James Smart3621a712009-04-06 18:47:14 -04001937 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04001938 * @phba: pointer to lpfc hba data structure.
1939 *
1940 * This routine marks a HBA's management interface as not blocked. Once the
1941 * HBA's management interface is marked as not blocked, all the user space
1942 * access to the HBA, whether they are from sysfs interface or libdfc
1943 * interface will be allowed. The HBA is set to block the management interface
1944 * when the driver prepares the HBA interface for online or offline and then
1945 * set to unblock the management interface afterwards.
1946 **/
James Smart46fa3112007-04-25 09:51:45 -04001947void
James Smart46fa3112007-04-25 09:51:45 -04001948lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1949{
1950 unsigned long iflag;
1951
James Smart2e0fef82007-06-17 19:56:36 -05001952 spin_lock_irqsave(&phba->hbalock, iflag);
1953 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1954 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04001955}
1956
James Smarte59058c2008-08-24 21:49:00 -04001957/**
James Smart3621a712009-04-06 18:47:14 -04001958 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04001959 * @phba: pointer to lpfc hba data structure.
1960 *
1961 * This routine is invoked to prepare a HBA to be brought offline. It performs
1962 * unregistration login to all the nodes on all vports and flushes the mailbox
1963 * queue to make it ready to be brought offline.
1964 **/
James Smart46fa3112007-04-25 09:51:45 -04001965void
1966lpfc_offline_prep(struct lpfc_hba * phba)
1967{
James Smart2e0fef82007-06-17 19:56:36 -05001968 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04001969 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04001970 struct lpfc_vport **vports;
1971 int i;
dea31012005-04-17 16:05:31 -05001972
James Smart2e0fef82007-06-17 19:56:36 -05001973 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04001974 return;
dea31012005-04-17 16:05:31 -05001975
James Smart46fa3112007-04-25 09:51:45 -04001976 lpfc_block_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001977
1978 lpfc_linkdown(phba);
1979
James Smart87af33f2007-10-27 13:37:43 -04001980 /* Issue an unreg_login to all nodes on all vports */
1981 vports = lpfc_create_vport_work_array(phba);
1982 if (vports != NULL) {
James Smart09372822008-01-11 01:52:54 -05001983 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart87af33f2007-10-27 13:37:43 -04001984 struct Scsi_Host *shost;
1985
James Smarta8adb832007-10-27 13:37:53 -04001986 if (vports[i]->load_flag & FC_UNLOADING)
1987 continue;
James Smart87af33f2007-10-27 13:37:43 -04001988 shost = lpfc_shost_from_vport(vports[i]);
1989 list_for_each_entry_safe(ndlp, next_ndlp,
1990 &vports[i]->fc_nodes,
1991 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05001992 if (!NLP_CHK_NODE_ACT(ndlp))
1993 continue;
James Smart87af33f2007-10-27 13:37:43 -04001994 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1995 continue;
1996 if (ndlp->nlp_type & NLP_FABRIC) {
1997 lpfc_disc_state_machine(vports[i], ndlp,
1998 NULL, NLP_EVT_DEVICE_RECOVERY);
1999 lpfc_disc_state_machine(vports[i], ndlp,
2000 NULL, NLP_EVT_DEVICE_RM);
2001 }
2002 spin_lock_irq(shost->host_lock);
2003 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2004 spin_unlock_irq(shost->host_lock);
2005 lpfc_unreg_rpi(vports[i], ndlp);
2006 }
2007 }
2008 }
James Smart09372822008-01-11 01:52:54 -05002009 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002010
James Smart46fa3112007-04-25 09:51:45 -04002011 lpfc_sli_flush_mbox_queue(phba);
2012}
2013
James Smarte59058c2008-08-24 21:49:00 -04002014/**
James Smart3621a712009-04-06 18:47:14 -04002015 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04002016 * @phba: pointer to lpfc hba data structure.
2017 *
2018 * This routine actually brings a HBA offline. It stops all the timers
2019 * associated with the HBA, brings down the SLI layer, and eventually
2020 * marks the HBA as in offline state for the upper layer protocol.
2021 **/
James Smart46fa3112007-04-25 09:51:45 -04002022void
James Smart2e0fef82007-06-17 19:56:36 -05002023lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04002024{
James Smart549e55c2007-08-02 11:09:51 -04002025 struct Scsi_Host *shost;
2026 struct lpfc_vport **vports;
2027 int i;
James Smart46fa3112007-04-25 09:51:45 -04002028
James Smart549e55c2007-08-02 11:09:51 -04002029 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04002030 return;
James Smart688a8862006-07-06 15:49:56 -04002031
dea31012005-04-17 16:05:31 -05002032 /* stop all timers associated with this hba */
James Smart92d7f7b2007-06-17 19:56:38 -05002033 lpfc_stop_phba_timers(phba);
James Smart51ef4c22007-08-02 11:10:31 -04002034 vports = lpfc_create_vport_work_array(phba);
2035 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05002036 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04002037 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05002038 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05002039 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002040 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05002041 /* Bring down the SLI Layer and cleanup. The HBA is offline
2042 now. */
2043 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002044 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04002045 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002046 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04002047 vports = lpfc_create_vport_work_array(phba);
2048 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -05002049 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002050 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04002051 spin_lock_irq(shost->host_lock);
2052 vports[i]->work_port_events = 0;
2053 vports[i]->fc_flag |= FC_OFFLINE_MODE;
2054 spin_unlock_irq(shost->host_lock);
2055 }
James Smart09372822008-01-11 01:52:54 -05002056 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002057}
2058
James Smarte59058c2008-08-24 21:49:00 -04002059/**
James Smart3621a712009-04-06 18:47:14 -04002060 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04002061 * @phba: pointer to lpfc hba data structure.
2062 *
2063 * This routine is to free all the SCSI buffers and IOCBs from the driver
2064 * list back to kernel. It is called from lpfc_pci_remove_one to free
2065 * the internal resources before the device is removed from the system.
2066 *
2067 * Return codes
2068 * 0 - successful (for now, it always returns 0)
2069 **/
dea31012005-04-17 16:05:31 -05002070static int
James Smart2e0fef82007-06-17 19:56:36 -05002071lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002072{
2073 struct lpfc_scsi_buf *sb, *sb_next;
2074 struct lpfc_iocbq *io, *io_next;
2075
James Smart2e0fef82007-06-17 19:56:36 -05002076 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002077 /* Release all the lpfc_scsi_bufs maintained by this host. */
2078 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
2079 list_del(&sb->list);
2080 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05002081 sb->dma_handle);
dea31012005-04-17 16:05:31 -05002082 kfree(sb);
2083 phba->total_scsi_bufs--;
2084 }
2085
2086 /* Release all the lpfc_iocbq entries maintained by this host. */
2087 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
2088 list_del(&io->list);
2089 kfree(io);
2090 phba->total_iocbq_bufs--;
2091 }
2092
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002094
2095 return 0;
2096}
2097
James Smarte59058c2008-08-24 21:49:00 -04002098/**
James Smart3621a712009-04-06 18:47:14 -04002099 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04002100 * @phba: pointer to lpfc hba data structure.
2101 * @instance: a unique integer ID to this FC port.
2102 * @dev: pointer to the device data structure.
2103 *
2104 * This routine creates a FC port for the upper layer protocol. The FC port
2105 * can be created on top of either a physical port or a virtual port provided
2106 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2107 * and associates the FC port created before adding the shost into the SCSI
2108 * layer.
2109 *
2110 * Return codes
2111 * @vport - pointer to the virtual N_Port data structure.
2112 * NULL - port create failed.
2113 **/
James Smart2e0fef82007-06-17 19:56:36 -05002114struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04002115lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04002116{
James Smart2e0fef82007-06-17 19:56:36 -05002117 struct lpfc_vport *vport;
2118 struct Scsi_Host *shost;
2119 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04002120
James Smart3de2a652007-08-02 11:09:59 -04002121 if (dev != &phba->pcidev->dev)
2122 shost = scsi_host_alloc(&lpfc_vport_template,
2123 sizeof(struct lpfc_vport));
2124 else
2125 shost = scsi_host_alloc(&lpfc_template,
2126 sizeof(struct lpfc_vport));
James Smart2e0fef82007-06-17 19:56:36 -05002127 if (!shost)
2128 goto out;
James Smart47a86172007-04-25 09:53:22 -04002129
James Smart2e0fef82007-06-17 19:56:36 -05002130 vport = (struct lpfc_vport *) shost->hostdata;
2131 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05002132 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05002133 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05002134 vport->fc_rscn_flush = 0;
James Smart47a86172007-04-25 09:53:22 -04002135
James Smart3de2a652007-08-02 11:09:59 -04002136 lpfc_get_vport_cfgparam(vport);
James Smart2e0fef82007-06-17 19:56:36 -05002137 shost->unique_id = instance;
2138 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04002139 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05002140 shost->this_id = -1;
2141 shost->max_cmd_len = 16;
James Smart81301a92008-12-04 22:39:46 -05002142
James Smart47a86172007-04-25 09:53:22 -04002143 /*
James Smart2e0fef82007-06-17 19:56:36 -05002144 * Set initial can_queue value since 0 is no longer supported and
2145 * scsi_add_host will fail. This will be adjusted later based on the
2146 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04002147 */
James Smart2e0fef82007-06-17 19:56:36 -05002148 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04002149 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05002150 shost->transportt = lpfc_vport_transport_template;
2151 vport->port_type = LPFC_NPIV_PORT;
2152 } else {
2153 shost->transportt = lpfc_transport_template;
2154 vport->port_type = LPFC_PHYSICAL_PORT;
2155 }
James Smart47a86172007-04-25 09:53:22 -04002156
James Smart2e0fef82007-06-17 19:56:36 -05002157 /* Initialize all internally managed lists. */
2158 INIT_LIST_HEAD(&vport->fc_nodes);
2159 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04002160
James Smart2e0fef82007-06-17 19:56:36 -05002161 init_timer(&vport->fc_disctmo);
2162 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002163 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002164
James Smart2e0fef82007-06-17 19:56:36 -05002165 init_timer(&vport->fc_fdmitmo);
2166 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
James Smart92d7f7b2007-06-17 19:56:38 -05002167 vport->fc_fdmitmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002168
James Smart2e0fef82007-06-17 19:56:36 -05002169 init_timer(&vport->els_tmofunc);
2170 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05002171 vport->els_tmofunc.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04002172
James Smart3de2a652007-08-02 11:09:59 -04002173 error = scsi_add_host(shost, dev);
James Smart2e0fef82007-06-17 19:56:36 -05002174 if (error)
2175 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04002176
James Smart549e55c2007-08-02 11:09:51 -04002177 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002178 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04002179 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05002180 return vport;
James Smart47a86172007-04-25 09:53:22 -04002181
James Smart2e0fef82007-06-17 19:56:36 -05002182out_put_shost:
2183 scsi_host_put(shost);
2184out:
2185 return NULL;
James Smart47a86172007-04-25 09:53:22 -04002186}
2187
James Smarte59058c2008-08-24 21:49:00 -04002188/**
James Smart3621a712009-04-06 18:47:14 -04002189 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04002190 * @vport: pointer to an lpfc virtual N_Port data structure.
2191 *
2192 * This routine destroys a FC port from the upper layer protocol. All the
2193 * resources associated with the port are released.
2194 **/
James Smart2e0fef82007-06-17 19:56:36 -05002195void
2196destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04002197{
James Smart92d7f7b2007-06-17 19:56:38 -05002198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2199 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002200
James Smart858c9f62007-06-17 19:56:39 -05002201 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002202 fc_remove_host(shost);
2203 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04002204
James Smart92d7f7b2007-06-17 19:56:38 -05002205 spin_lock_irq(&phba->hbalock);
2206 list_del_init(&vport->listentry);
2207 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04002208
James Smart92d7f7b2007-06-17 19:56:38 -05002209 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04002210 return;
James Smart47a86172007-04-25 09:53:22 -04002211}
2212
James Smarte59058c2008-08-24 21:49:00 -04002213/**
James Smart3621a712009-04-06 18:47:14 -04002214 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04002215 *
2216 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2217 * uses the kernel idr facility to perform the task.
2218 *
2219 * Return codes:
2220 * instance - a unique integer ID allocated as the new instance.
2221 * -1 - lpfc get instance failed.
2222 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002223int
2224lpfc_get_instance(void)
2225{
2226 int instance = 0;
2227
2228 /* Assign an unused number */
2229 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2230 return -1;
2231 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2232 return -1;
2233 return instance;
2234}
2235
James Smarte59058c2008-08-24 21:49:00 -04002236/**
James Smart3621a712009-04-06 18:47:14 -04002237 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04002238 * @shost: pointer to SCSI host data structure.
2239 * @time: elapsed time of the scan in jiffies.
2240 *
2241 * This routine is called by the SCSI layer with a SCSI host to determine
2242 * whether the scan host is finished.
2243 *
2244 * Note: there is no scan_start function as adapter initialization will have
2245 * asynchronously kicked off the link initialization.
2246 *
2247 * Return codes
2248 * 0 - SCSI host scan is not over yet.
2249 * 1 - SCSI host scan is over.
2250 **/
James Smart47a86172007-04-25 09:53:22 -04002251int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2252{
James Smart2e0fef82007-06-17 19:56:36 -05002253 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2254 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05002255 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04002256
James Smart858c9f62007-06-17 19:56:39 -05002257 spin_lock_irq(shost->host_lock);
2258
James Smart51ef4c22007-08-02 11:10:31 -04002259 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05002260 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002261 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05002262 }
James Smart2e0fef82007-06-17 19:56:36 -05002263 if (time >= 30 * HZ) {
2264 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002265 "0461 Scanning longer than 30 "
2266 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002267 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002268 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002269 }
2270 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2271 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002272 "0465 Link down longer than 15 "
2273 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05002274 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002275 goto finished;
James Smart47a86172007-04-25 09:53:22 -04002276 }
2277
James Smart2e0fef82007-06-17 19:56:36 -05002278 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05002279 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002280 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05002281 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002282 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
James Smart858c9f62007-06-17 19:56:39 -05002283 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05002284 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05002285 goto finished;
2286
2287 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04002288
2289finished:
James Smart858c9f62007-06-17 19:56:39 -05002290 spin_unlock_irq(shost->host_lock);
2291 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05002292}
2293
James Smarte59058c2008-08-24 21:49:00 -04002294/**
James Smart3621a712009-04-06 18:47:14 -04002295 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04002296 * @shost: pointer to SCSI host data structure.
2297 *
2298 * This routine initializes a given SCSI host attributes on a FC port. The
2299 * SCSI host can be either on top of a physical port or a virtual port.
2300 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002301void lpfc_host_attrib_init(struct Scsi_Host *shost)
2302{
2303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2304 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04002305 /*
James Smart2e0fef82007-06-17 19:56:36 -05002306 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04002307 */
2308
James Smart2e0fef82007-06-17 19:56:36 -05002309 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2310 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04002311 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2312
2313 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002314 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002315 fc_host_supported_fc4s(shost)[2] = 1;
2316 fc_host_supported_fc4s(shost)[7] = 1;
2317
James Smart92d7f7b2007-06-17 19:56:38 -05002318 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2319 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04002320
2321 fc_host_supported_speeds(shost) = 0;
2322 if (phba->lmt & LMT_10Gb)
2323 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04002324 if (phba->lmt & LMT_8Gb)
2325 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04002326 if (phba->lmt & LMT_4Gb)
2327 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2328 if (phba->lmt & LMT_2Gb)
2329 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2330 if (phba->lmt & LMT_1Gb)
2331 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2332
2333 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05002334 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2335 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04002336
2337 /* This value is also unchanging */
2338 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05002339 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04002340 fc_host_active_fc4s(shost)[2] = 1;
2341 fc_host_active_fc4s(shost)[7] = 1;
2342
James Smart92d7f7b2007-06-17 19:56:38 -05002343 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04002344 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04002345 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04002346 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04002347}
dea31012005-04-17 16:05:31 -05002348
James Smarte59058c2008-08-24 21:49:00 -04002349/**
James Smart3621a712009-04-06 18:47:14 -04002350 * lpfc_enable_msix - Enable MSI-X interrupt mode
James Smarte59058c2008-08-24 21:49:00 -04002351 * @phba: pointer to lpfc hba data structure.
2352 *
2353 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2354 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2355 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2356 * on the current availability of PCI vector resources. The device driver is
2357 * responsible for calling the individual request_irq() to register each MSI-X
2358 * vector with a interrupt handler, which is done in this function. Note that
2359 * later when device is unloading, the driver should always call free_irq()
2360 * on all MSI-X vectors it has done request_irq() on before calling
2361 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2362 * will be left with MSI-X enabled and leaks its vectors.
2363 *
2364 * Return codes
2365 * 0 - sucessful
2366 * other values - error
2367 **/
James Smartdb2378e2008-02-08 18:49:51 -05002368static int
2369lpfc_enable_msix(struct lpfc_hba *phba)
2370{
James Smart93996272008-08-24 21:50:30 -04002371 int rc, i;
2372 LPFC_MBOXQ_t *pmb;
James Smartdb2378e2008-02-08 18:49:51 -05002373
James Smart93996272008-08-24 21:50:30 -04002374 /* Set up MSI-X multi-message vectors */
2375 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2376 phba->msix_entries[i].entry = i;
James Smartdb2378e2008-02-08 18:49:51 -05002377
James Smart93996272008-08-24 21:50:30 -04002378 /* Configure MSI-X capability structure */
2379 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
James Smartdb2378e2008-02-08 18:49:51 -05002380 ARRAY_SIZE(phba->msix_entries));
James Smart93996272008-08-24 21:50:30 -04002381 if (rc) {
James Smartdb2378e2008-02-08 18:49:51 -05002382 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05002383 "0420 PCI enable MSI-X failed (%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002384 goto msi_fail_out;
2385 } else
2386 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2387 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2388 "0477 MSI-X entry[%d]: vector=x%x "
2389 "message=%d\n", i,
2390 phba->msix_entries[i].vector,
2391 phba->msix_entries[i].entry);
2392 /*
2393 * Assign MSI-X vectors to interrupt handlers
2394 */
2395
2396 /* vector-0 is associated to slow-path handler */
2397 rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler,
2398 IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba);
2399 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002400 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002401 "0421 MSI-X slow-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002402 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002403 goto msi_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002404 }
2405
James Smart93996272008-08-24 21:50:30 -04002406 /* vector-1 is associated to fast-path handler */
2407 rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler,
2408 IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba);
2409
2410 if (rc) {
James Smart5b75da22008-12-04 22:39:35 -05002411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smart93996272008-08-24 21:50:30 -04002412 "0429 MSI-X fast-path request_irq failed "
James Smart5b75da22008-12-04 22:39:35 -05002413 "(%d)\n", rc);
James Smart93996272008-08-24 21:50:30 -04002414 goto irq_fail_out;
James Smartdb2378e2008-02-08 18:49:51 -05002415 }
James Smart93996272008-08-24 21:50:30 -04002416
2417 /*
2418 * Configure HBA MSI-X attention conditions to messages
2419 */
2420 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2421
2422 if (!pmb) {
2423 rc = -ENOMEM;
2424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2425 "0474 Unable to allocate memory for issuing "
2426 "MBOX_CONFIG_MSI command\n");
2427 goto mem_fail_out;
2428 }
2429 rc = lpfc_config_msi(phba, pmb);
2430 if (rc)
2431 goto mbx_fail_out;
2432 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
2433 if (rc != MBX_SUCCESS) {
James Smart5b75da22008-12-04 22:39:35 -05002434 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smart93996272008-08-24 21:50:30 -04002435 "0351 Config MSI mailbox command failed, "
2436 "mbxCmd x%x, mbxStatus x%x\n",
2437 pmb->mb.mbxCommand, pmb->mb.mbxStatus);
2438 goto mbx_fail_out;
2439 }
2440
2441 /* Free memory allocated for mailbox command */
2442 mempool_free(pmb, phba->mbox_mem_pool);
2443 return rc;
2444
2445mbx_fail_out:
2446 /* Free memory allocated for mailbox command */
2447 mempool_free(pmb, phba->mbox_mem_pool);
2448
2449mem_fail_out:
2450 /* free the irq already requested */
2451 free_irq(phba->msix_entries[1].vector, phba);
2452
2453irq_fail_out:
2454 /* free the irq already requested */
2455 free_irq(phba->msix_entries[0].vector, phba);
2456
2457msi_fail_out:
2458 /* Unconfigure MSI-X capability structure */
2459 pci_disable_msix(phba->pcidev);
2460 return rc;
James Smartdb2378e2008-02-08 18:49:51 -05002461}
2462
James Smarte59058c2008-08-24 21:49:00 -04002463/**
James Smart3621a712009-04-06 18:47:14 -04002464 * lpfc_disable_msix - Disable MSI-X interrupt mode
James Smarte59058c2008-08-24 21:49:00 -04002465 * @phba: pointer to lpfc hba data structure.
2466 *
2467 * This routine is invoked to release the MSI-X vectors and then disable the
2468 * MSI-X interrupt mode.
2469 **/
James Smartdb2378e2008-02-08 18:49:51 -05002470static void
2471lpfc_disable_msix(struct lpfc_hba *phba)
2472{
James Smart93996272008-08-24 21:50:30 -04002473 int i;
2474
2475 /* Free up MSI-X multi-message vectors */
2476 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
2477 free_irq(phba->msix_entries[i].vector, phba);
2478 /* Disable MSI-X */
James Smartdb2378e2008-02-08 18:49:51 -05002479 pci_disable_msix(phba->pcidev);
2480}
2481
James Smarte59058c2008-08-24 21:49:00 -04002482/**
James Smart3621a712009-04-06 18:47:14 -04002483 * lpfc_enable_msi - Enable MSI interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05002484 * @phba: pointer to lpfc hba data structure.
2485 *
2486 * This routine is invoked to enable the MSI interrupt mode. The kernel
2487 * function pci_enable_msi() is called to enable the MSI vector. The
2488 * device driver is responsible for calling the request_irq() to register
2489 * MSI vector with a interrupt the handler, which is done in this function.
2490 *
2491 * Return codes
2492 * 0 - sucessful
2493 * other values - error
2494 */
2495static int
2496lpfc_enable_msi(struct lpfc_hba *phba)
2497{
2498 int rc;
2499
2500 rc = pci_enable_msi(phba->pcidev);
2501 if (!rc)
2502 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2503 "0462 PCI enable MSI mode success.\n");
2504 else {
2505 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2506 "0471 PCI enable MSI mode failed (%d)\n", rc);
2507 return rc;
2508 }
2509
2510 rc = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2511 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2512 if (rc) {
2513 pci_disable_msi(phba->pcidev);
2514 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2515 "0478 MSI request_irq failed (%d)\n", rc);
2516 }
2517 return rc;
2518}
2519
2520/**
James Smart3621a712009-04-06 18:47:14 -04002521 * lpfc_disable_msi - Disable MSI interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05002522 * @phba: pointer to lpfc hba data structure.
2523 *
2524 * This routine is invoked to disable the MSI interrupt mode. The driver
2525 * calls free_irq() on MSI vector it has done request_irq() on before
2526 * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and
2527 * a device will be left with MSI enabled and leaks its vector.
2528 */
2529
2530static void
2531lpfc_disable_msi(struct lpfc_hba *phba)
2532{
2533 free_irq(phba->pcidev->irq, phba);
2534 pci_disable_msi(phba->pcidev);
2535 return;
2536}
2537
2538/**
James Smart3621a712009-04-06 18:47:14 -04002539 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05002540 * @phba: pointer to lpfc hba data structure.
2541 * @intr_mode: active interrupt mode adopted.
2542 *
2543 * This routine it invoked to log the currently used active interrupt mode
2544 * to the device.
James Smart3772a992009-05-22 14:50:54 -04002545 **/
2546static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05002547{
2548 switch (intr_mode) {
2549 case 0:
2550 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2551 "0470 Enable INTx interrupt mode.\n");
2552 break;
2553 case 1:
2554 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2555 "0481 Enabled MSI interrupt mode.\n");
2556 break;
2557 case 2:
2558 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2559 "0480 Enabled MSI-X interrupt mode.\n");
2560 break;
2561 default:
2562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2563 "0482 Illegal interrupt mode.\n");
2564 break;
2565 }
2566 return;
2567}
2568
James Smart5b75da22008-12-04 22:39:35 -05002569/**
James Smart3772a992009-05-22 14:50:54 -04002570 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05002571 * @phba: pointer to lpfc hba data structure.
2572 *
James Smart3772a992009-05-22 14:50:54 -04002573 * This routine is invoked to enable the PCI device that is common to all
2574 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05002575 *
2576 * Return codes
James Smart3772a992009-05-22 14:50:54 -04002577 * 0 - sucessful
2578 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05002579 **/
James Smart3772a992009-05-22 14:50:54 -04002580static int
2581lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05002582{
James Smart3772a992009-05-22 14:50:54 -04002583 struct pci_dev *pdev;
2584 int bars;
James Smart5b75da22008-12-04 22:39:35 -05002585
James Smart3772a992009-05-22 14:50:54 -04002586 /* Obtain PCI device reference */
2587 if (!phba->pcidev)
2588 goto out_error;
2589 else
2590 pdev = phba->pcidev;
2591 /* Select PCI BARs */
2592 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2593 /* Enable PCI device */
2594 if (pci_enable_device_mem(pdev))
2595 goto out_error;
2596 /* Request PCI resource for the device */
2597 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
2598 goto out_disable_device;
2599 /* Set up device as PCI master and save state for EEH */
2600 pci_set_master(pdev);
2601 pci_try_set_mwi(pdev);
2602 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05002603
James Smart3772a992009-05-22 14:50:54 -04002604 return 0;
James Smart5b75da22008-12-04 22:39:35 -05002605
James Smart3772a992009-05-22 14:50:54 -04002606out_disable_device:
2607 pci_disable_device(pdev);
2608out_error:
2609 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05002610}
2611
2612/**
James Smart3772a992009-05-22 14:50:54 -04002613 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05002614 * @phba: pointer to lpfc hba data structure.
2615 *
James Smart3772a992009-05-22 14:50:54 -04002616 * This routine is invoked to disable the PCI device that is common to all
2617 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05002618 **/
2619static void
James Smart3772a992009-05-22 14:50:54 -04002620lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05002621{
James Smart3772a992009-05-22 14:50:54 -04002622 struct pci_dev *pdev;
2623 int bars;
James Smart5b75da22008-12-04 22:39:35 -05002624
James Smart3772a992009-05-22 14:50:54 -04002625 /* Obtain PCI device reference */
2626 if (!phba->pcidev)
2627 return;
2628 else
2629 pdev = phba->pcidev;
2630 /* Select PCI BARs */
2631 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2632 /* Release PCI resource and disable PCI device */
2633 pci_release_selected_regions(pdev, bars);
2634 pci_disable_device(pdev);
2635 /* Null out PCI private reference to driver */
2636 pci_set_drvdata(pdev, NULL);
James Smart5b75da22008-12-04 22:39:35 -05002637
2638 return;
2639}
2640
2641/**
James Smart3772a992009-05-22 14:50:54 -04002642 * lpfc_reset_hba - Reset a hba
2643 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04002644 *
James Smart3772a992009-05-22 14:50:54 -04002645 * This routine is invoked to reset a hba device. It brings the HBA
2646 * offline, performs a board restart, and then brings the board back
2647 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
2648 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04002649 **/
James Smart3772a992009-05-22 14:50:54 -04002650void
2651lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002652{
James Smart3772a992009-05-22 14:50:54 -04002653 /* If resets are disabled then set error state and return. */
2654 if (!phba->cfg_enable_hba_reset) {
2655 phba->link_state = LPFC_HBA_ERROR;
2656 return;
2657 }
2658 lpfc_offline_prep(phba);
2659 lpfc_offline(phba);
2660 lpfc_sli_brdrestart(phba);
2661 lpfc_online(phba);
2662 lpfc_unblock_mgmt_io(phba);
2663}
dea31012005-04-17 16:05:31 -05002664
James Smart3772a992009-05-22 14:50:54 -04002665/**
2666 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
2667 * @phba: pointer to lpfc hba data structure.
2668 *
2669 * This routine is invoked to set up the driver internal resources specific to
2670 * support the SLI-3 HBA device it attached to.
2671 *
2672 * Return codes
2673 * 0 - sucessful
2674 * other values - error
2675 **/
2676static int
2677lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
2678{
2679 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002680
James Smart3772a992009-05-22 14:50:54 -04002681 /*
2682 * Initialize timers used by driver
2683 */
dea31012005-04-17 16:05:31 -05002684
James Smart3772a992009-05-22 14:50:54 -04002685 /* Heartbeat timer */
2686 init_timer(&phba->hb_tmofunc);
2687 phba->hb_tmofunc.function = lpfc_hb_timeout;
2688 phba->hb_tmofunc.data = (unsigned long)phba;
2689
2690 psli = &phba->sli;
2691 /* MBOX heartbeat timer */
2692 init_timer(&psli->mbox_tmo);
2693 psli->mbox_tmo.function = lpfc_mbox_timeout;
2694 psli->mbox_tmo.data = (unsigned long) phba;
2695 /* FCP polling mode timer */
2696 init_timer(&phba->fcp_poll_timer);
2697 phba->fcp_poll_timer.function = lpfc_poll_timeout;
2698 phba->fcp_poll_timer.data = (unsigned long) phba;
2699 /* Fabric block timer */
2700 init_timer(&phba->fabric_block_timer);
2701 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2702 phba->fabric_block_timer.data = (unsigned long) phba;
2703 /* EA polling mode timer */
2704 init_timer(&phba->eratt_poll);
2705 phba->eratt_poll.function = lpfc_poll_eratt;
2706 phba->eratt_poll.data = (unsigned long) phba;
2707
2708 /* Host attention work mask setup */
2709 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
2710 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2711
2712 /* Get all the module params for configuring this host */
2713 lpfc_get_cfgparam(phba);
2714 /*
2715 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2716 * used to create the sg_dma_buf_pool must be dynamically calculated.
2717 * 2 segments are added since the IOCB needs a command and response bde.
2718 */
2719 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2720 sizeof(struct fcp_rsp) +
2721 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
2722
2723 if (phba->cfg_enable_bg) {
2724 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
2725 phba->cfg_sg_dma_buf_size +=
2726 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
2727 }
2728
2729 /* Also reinitialize the host templates with new values. */
2730 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
2731 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
2732
2733 phba->max_vpi = LPFC_MAX_VPI;
2734 /* This will be set to correct value after config_port mbox */
2735 phba->max_vports = 0;
2736
2737 /*
2738 * Initialize the SLI Layer to run with lpfc HBAs.
2739 */
2740 lpfc_sli_setup(phba);
2741 lpfc_sli_queue_setup(phba);
2742
2743 /* Allocate device driver memory */
2744 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
2745 return -ENOMEM;
2746
2747 return 0;
2748}
2749
2750/**
2751 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
2752 * @phba: pointer to lpfc hba data structure.
2753 *
2754 * This routine is invoked to unset the driver internal resources set up
2755 * specific for supporting the SLI-3 HBA device it attached to.
2756 **/
2757static void
2758lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
2759{
2760 /* Free device driver memory allocated */
2761 lpfc_mem_free_all(phba);
2762
2763 return;
2764}
2765
2766/**
2767 * lpfc_init_api_table_setup - Set up init api fucntion jump table
2768 * @phba: The hba struct for which this call is being executed.
2769 * @dev_grp: The HBA PCI-Device group number.
2770 *
2771 * This routine sets up the device INIT interface API function jump table
2772 * in @phba struct.
2773 *
2774 * Returns: 0 - success, -ENODEV - failure.
2775 **/
2776int
2777lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2778{
2779 switch (dev_grp) {
2780 case LPFC_PCI_DEV_LP:
2781 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
2782 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
2783 phba->lpfc_stop_port = lpfc_stop_port_s3;
2784 break;
2785 default:
2786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2787 "1431 Invalid HBA PCI-device group: 0x%x\n",
2788 dev_grp);
2789 return -ENODEV;
2790 break;
2791 }
2792 return 0;
2793}
2794
2795/**
2796 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
2797 * @phba: pointer to lpfc hba data structure.
2798 *
2799 * This routine is invoked to set up the driver internal resources before the
2800 * device specific resource setup to support the HBA device it attached to.
2801 *
2802 * Return codes
2803 * 0 - sucessful
2804 * other values - error
2805 **/
2806static int
2807lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
2808{
2809 /*
2810 * Driver resources common to all SLI revisions
2811 */
James Smartea2151b2008-09-07 11:52:10 -04002812 atomic_set(&phba->fast_event_count, 0);
James Smart2e0fef82007-06-17 19:56:36 -05002813 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002814
James Smarte47c9092008-02-08 18:49:26 -05002815 /* Initialize ndlp management spinlock */
2816 spin_lock_init(&phba->ndlp_lock);
2817
James Smart2e0fef82007-06-17 19:56:36 -05002818 INIT_LIST_HEAD(&phba->port_list);
James Smart3772a992009-05-22 14:50:54 -04002819 INIT_LIST_HEAD(&phba->work_list);
James Smart84774a42008-08-24 21:50:06 -04002820 init_waitqueue_head(&phba->wait_4_mlo_m_q);
dea31012005-04-17 16:05:31 -05002821
James Smart3772a992009-05-22 14:50:54 -04002822 /* Initialize the wait queue head for the kernel thread */
2823 init_waitqueue_head(&phba->work_waitq);
James Smart858c9f62007-06-17 19:56:39 -05002824
James Smart3772a992009-05-22 14:50:54 -04002825 /* Initialize the scsi buffer list used by driver for scsi IO */
2826 spin_lock_init(&phba->scsi_buf_list_lock);
2827 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
dea31012005-04-17 16:05:31 -05002828
James Smart3772a992009-05-22 14:50:54 -04002829 /* Initialize the fabric iocb list */
2830 INIT_LIST_HEAD(&phba->fabric_iocb_list);
dea31012005-04-17 16:05:31 -05002831
James Smart3772a992009-05-22 14:50:54 -04002832 /* Initialize list to save ELS buffers */
2833 INIT_LIST_HEAD(&phba->elsbuf);
dea31012005-04-17 16:05:31 -05002834
James Smart3772a992009-05-22 14:50:54 -04002835 /* Initialize FCF connection rec list */
2836 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
dea31012005-04-17 16:05:31 -05002837
James Smart3772a992009-05-22 14:50:54 -04002838 return 0;
2839}
dea31012005-04-17 16:05:31 -05002840
James Smart3772a992009-05-22 14:50:54 -04002841/**
2842 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
2843 * @phba: pointer to lpfc hba data structure.
2844 *
2845 * This routine is invoked to set up the driver internal resources after the
2846 * device specific resource setup to support the HBA device it attached to.
2847 *
2848 * Return codes
2849 * 0 - sucessful
2850 * other values - error
2851 **/
2852static int
2853lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
2854{
2855 int error;
2856
2857 /* Startup the kernel thread for this host adapter. */
2858 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2859 "lpfc_worker_%d", phba->brd_no);
2860 if (IS_ERR(phba->worker_thread)) {
2861 error = PTR_ERR(phba->worker_thread);
2862 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002863 }
2864
James Smart3772a992009-05-22 14:50:54 -04002865 return 0;
2866}
2867
2868/**
2869 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
2870 * @phba: pointer to lpfc hba data structure.
2871 *
2872 * This routine is invoked to unset the driver internal resources set up after
2873 * the device specific resource setup for supporting the HBA device it
2874 * attached to.
2875 **/
2876static void
2877lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
2878{
2879 /* Stop kernel worker thread */
2880 kthread_stop(phba->worker_thread);
2881}
2882
2883/**
2884 * lpfc_free_iocb_list - Free iocb list.
2885 * @phba: pointer to lpfc hba data structure.
2886 *
2887 * This routine is invoked to free the driver's IOCB list and memory.
2888 **/
2889static void
2890lpfc_free_iocb_list(struct lpfc_hba *phba)
2891{
2892 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
2893
2894 spin_lock_irq(&phba->hbalock);
2895 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2896 &phba->lpfc_iocb_list, list) {
2897 list_del(&iocbq_entry->list);
2898 kfree(iocbq_entry);
2899 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05002900 }
James Smart3772a992009-05-22 14:50:54 -04002901 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002902
James Smart3772a992009-05-22 14:50:54 -04002903 return;
2904}
dea31012005-04-17 16:05:31 -05002905
James Smart3772a992009-05-22 14:50:54 -04002906/**
2907 * lpfc_init_iocb_list - Allocate and initialize iocb list.
2908 * @phba: pointer to lpfc hba data structure.
2909 *
2910 * This routine is invoked to allocate and initizlize the driver's IOCB
2911 * list and set up the IOCB tag array accordingly.
2912 *
2913 * Return codes
2914 * 0 - sucessful
2915 * other values - error
2916 **/
2917static int
2918lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
2919{
2920 struct lpfc_iocbq *iocbq_entry = NULL;
2921 uint16_t iotag;
2922 int i;
dea31012005-04-17 16:05:31 -05002923
2924 /* Initialize and populate the iocb list per host. */
2925 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04002926 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002927 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002928 if (iocbq_entry == NULL) {
2929 printk(KERN_ERR "%s: only allocated %d iocbs of "
2930 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07002931 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05002932 goto out_free_iocbq;
2933 }
2934
James Bottomley604a3e32005-10-29 10:28:33 -05002935 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2936 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04002937 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05002938 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04002939 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05002940 goto out_free_iocbq;
2941 }
James Smart3772a992009-05-22 14:50:54 -04002942 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05002943
2944 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002945 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2946 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05002947 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002948 }
2949
James Smart3772a992009-05-22 14:50:54 -04002950 return 0;
2951
2952out_free_iocbq:
2953 lpfc_free_iocb_list(phba);
2954
2955 return -ENOMEM;
2956}
2957
2958/**
2959 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
2960 * @pdev: pointer to pci device data structure.
2961 *
2962 * This routine is invoked to allocate the driver hba data structure for an
2963 * HBA device. If the allocation is successful, the phba reference to the
2964 * PCI device data structure is set.
2965 *
2966 * Return codes
2967 * pointer to @phba - sucessful
2968 * NULL - error
2969 **/
2970static struct lpfc_hba *
2971lpfc_hba_alloc(struct pci_dev *pdev)
2972{
2973 struct lpfc_hba *phba;
2974
2975 /* Allocate memory for HBA structure */
2976 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
2977 if (!phba) {
2978 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2979 "1417 Failed to allocate hba struct.\n");
2980 return NULL;
2981 }
2982
2983 /* Set reference to PCI device in HBA structure */
2984 phba->pcidev = pdev;
2985
2986 /* Assign an unused board number */
2987 phba->brd_no = lpfc_get_instance();
2988 if (phba->brd_no < 0) {
2989 kfree(phba);
2990 return NULL;
2991 }
2992
2993 return phba;
2994}
2995
2996/**
2997 * lpfc_hba_free - Free driver hba data structure with a device.
2998 * @phba: pointer to lpfc hba data structure.
2999 *
3000 * This routine is invoked to free the driver hba data structure with an
3001 * HBA device.
3002 **/
3003static void
3004lpfc_hba_free(struct lpfc_hba *phba)
3005{
3006 /* Release the driver assigned board number */
3007 idr_remove(&lpfc_hba_index, phba->brd_no);
3008
3009 kfree(phba);
3010 return;
3011}
3012
3013/**
3014 * lpfc_create_shost - Create hba physical port with associated scsi host.
3015 * @phba: pointer to lpfc hba data structure.
3016 *
3017 * This routine is invoked to create HBA physical port and associate a SCSI
3018 * host with it.
3019 *
3020 * Return codes
3021 * 0 - sucessful
3022 * other values - error
3023 **/
3024static int
3025lpfc_create_shost(struct lpfc_hba *phba)
3026{
3027 struct lpfc_vport *vport;
3028 struct Scsi_Host *shost;
3029
3030 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05003031 phba->fc_edtov = FF_DEF_EDTOV;
3032 phba->fc_ratov = FF_DEF_RATOV;
3033 phba->fc_altov = FF_DEF_ALTOV;
3034 phba->fc_arbtov = FF_DEF_ARBTOV;
3035
James Smart3de2a652007-08-02 11:09:59 -04003036 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003037 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04003038 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05003039
3040 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003041 phba->pport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003042 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04003043 /* Put reference to SCSI host to driver's device private data */
3044 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05003045
James Smart3772a992009-05-22 14:50:54 -04003046 return 0;
3047}
dea31012005-04-17 16:05:31 -05003048
James Smart3772a992009-05-22 14:50:54 -04003049/**
3050 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
3051 * @phba: pointer to lpfc hba data structure.
3052 *
3053 * This routine is invoked to destroy HBA physical port and the associated
3054 * SCSI host.
3055 **/
3056static void
3057lpfc_destroy_shost(struct lpfc_hba *phba)
3058{
3059 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04003060
James Smart3772a992009-05-22 14:50:54 -04003061 /* Destroy physical port that associated with the SCSI host */
3062 destroy_port(vport);
3063
3064 return;
3065}
3066
3067/**
3068 * lpfc_setup_bg - Setup Block guard structures and debug areas.
3069 * @phba: pointer to lpfc hba data structure.
3070 * @shost: the shost to be used to detect Block guard settings.
3071 *
3072 * This routine sets up the local Block guard protocol settings for @shost.
3073 * This routine also allocates memory for debugging bg buffers.
3074 **/
3075static void
3076lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
3077{
3078 int pagecnt = 10;
3079 if (lpfc_prot_mask && lpfc_prot_guard) {
3080 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3081 "1478 Registering BlockGuard with the "
3082 "SCSI layer\n");
3083 scsi_host_set_prot(shost, lpfc_prot_mask);
3084 scsi_host_set_guard(shost, lpfc_prot_guard);
James Smart98c9ea52007-10-27 13:37:33 -04003085 }
James Smart81301a92008-12-04 22:39:46 -05003086 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05003087 while (pagecnt) {
3088 spin_lock_init(&_dump_buf_lock);
3089 _dump_buf_data =
3090 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
3091 if (_dump_buf_data) {
3092 printk(KERN_ERR "BLKGRD allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04003093 "_dump_buf_data at 0x%p\n",
3094 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05003095 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04003096 memset(_dump_buf_data, 0,
3097 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05003098 break;
James Smart3772a992009-05-22 14:50:54 -04003099 } else
James Smart81301a92008-12-04 22:39:46 -05003100 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05003101 }
James Smart81301a92008-12-04 22:39:46 -05003102 if (!_dump_buf_data_order)
3103 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04003104 "memory for hexdump\n");
3105 } else
James Smart81301a92008-12-04 22:39:46 -05003106 printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p"
3107 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05003108 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05003109 while (pagecnt) {
3110 _dump_buf_dif =
3111 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
3112 if (_dump_buf_dif) {
3113 printk(KERN_ERR "BLKGRD allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04003114 "_dump_buf_dif at 0x%p\n",
3115 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05003116 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04003117 memset(_dump_buf_dif, 0,
3118 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05003119 break;
James Smart3772a992009-05-22 14:50:54 -04003120 } else
James Smart81301a92008-12-04 22:39:46 -05003121 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05003122 }
James Smart81301a92008-12-04 22:39:46 -05003123 if (!_dump_buf_dif_order)
3124 printk(KERN_ERR "BLKGRD ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04003125 "memory for hexdump\n");
3126 } else
James Smart81301a92008-12-04 22:39:46 -05003127 printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04003128 _dump_buf_dif);
3129}
3130
3131/**
3132 * lpfc_post_init_setup - Perform necessary device post initialization setup.
3133 * @phba: pointer to lpfc hba data structure.
3134 *
3135 * This routine is invoked to perform all the necessary post initialization
3136 * setup for the device.
3137 **/
3138static void
3139lpfc_post_init_setup(struct lpfc_hba *phba)
3140{
3141 struct Scsi_Host *shost;
3142 struct lpfc_adapter_event_header adapter_event;
3143
3144 /* Get the default values for Model Name and Description */
3145 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
3146
3147 /*
3148 * hba setup may have changed the hba_queue_depth so we need to
3149 * adjust the value of can_queue.
3150 */
3151 shost = pci_get_drvdata(phba->pcidev);
3152 shost->can_queue = phba->cfg_hba_queue_depth - 10;
3153 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
3154 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05003155
3156 lpfc_host_attrib_init(shost);
3157
James Smart2e0fef82007-06-17 19:56:36 -05003158 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
3159 spin_lock_irq(shost->host_lock);
3160 lpfc_poll_start_timer(phba);
3161 spin_unlock_irq(shost->host_lock);
3162 }
James Smart8f6d98d2006-08-01 07:34:00 -04003163
James Smart93996272008-08-24 21:50:30 -04003164 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3165 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04003166 /* Send board arrival event to upper layer */
3167 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
3168 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
3169 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04003170 sizeof(adapter_event),
3171 (char *) &adapter_event,
3172 LPFC_NL_VENDOR_ID);
3173 return;
3174}
3175
3176/**
3177 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
3178 * @phba: pointer to lpfc hba data structure.
3179 *
3180 * This routine is invoked to set up the PCI device memory space for device
3181 * with SLI-3 interface spec.
3182 *
3183 * Return codes
3184 * 0 - sucessful
3185 * other values - error
3186 **/
3187static int
3188lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
3189{
3190 struct pci_dev *pdev;
3191 unsigned long bar0map_len, bar2map_len;
3192 int i, hbq_count;
3193 void *ptr;
3194 int error = -ENODEV;
3195
3196 /* Obtain PCI device reference */
3197 if (!phba->pcidev)
3198 return error;
3199 else
3200 pdev = phba->pcidev;
3201
3202 /* Set the device DMA mask size */
3203 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
3204 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
3205 return error;
3206
3207 /* Get the bus address of Bar0 and Bar2 and the number of bytes
3208 * required by each mapping.
3209 */
3210 phba->pci_bar0_map = pci_resource_start(pdev, 0);
3211 bar0map_len = pci_resource_len(pdev, 0);
3212
3213 phba->pci_bar2_map = pci_resource_start(pdev, 2);
3214 bar2map_len = pci_resource_len(pdev, 2);
3215
3216 /* Map HBA SLIM to a kernel virtual address. */
3217 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
3218 if (!phba->slim_memmap_p) {
3219 dev_printk(KERN_ERR, &pdev->dev,
3220 "ioremap failed for SLIM memory.\n");
3221 goto out;
3222 }
3223
3224 /* Map HBA Control Registers to a kernel virtual address. */
3225 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
3226 if (!phba->ctrl_regs_memmap_p) {
3227 dev_printk(KERN_ERR, &pdev->dev,
3228 "ioremap failed for HBA control registers.\n");
3229 goto out_iounmap_slim;
3230 }
3231
3232 /* Allocate memory for SLI-2 structures */
3233 phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
3234 SLI2_SLIM_SIZE,
3235 &phba->slim2p.phys,
3236 GFP_KERNEL);
3237 if (!phba->slim2p.virt)
3238 goto out_iounmap;
3239
3240 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
3241 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
3242 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
3243 phba->IOCBs = (phba->slim2p.virt +
3244 offsetof(struct lpfc_sli2_slim, IOCBs));
3245
3246 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
3247 lpfc_sli_hbq_size(),
3248 &phba->hbqslimp.phys,
3249 GFP_KERNEL);
3250 if (!phba->hbqslimp.virt)
3251 goto out_free_slim;
3252
3253 hbq_count = lpfc_sli_hbq_count();
3254 ptr = phba->hbqslimp.virt;
3255 for (i = 0; i < hbq_count; ++i) {
3256 phba->hbqs[i].hbq_virt = ptr;
3257 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
3258 ptr += (lpfc_hbq_defs[i]->entry_count *
3259 sizeof(struct lpfc_hbq_entry));
3260 }
3261 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
3262 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
3263
3264 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
3265
3266 INIT_LIST_HEAD(&phba->rb_pend_list);
3267
3268 phba->MBslimaddr = phba->slim_memmap_p;
3269 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
3270 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
3271 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
3272 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04003273
dea31012005-04-17 16:05:31 -05003274 return 0;
3275
dea31012005-04-17 16:05:31 -05003276out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04003277 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
3278 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05003279out_iounmap:
3280 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05003281out_iounmap_slim:
dea31012005-04-17 16:05:31 -05003282 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05003283out:
3284 return error;
3285}
3286
James Smarte59058c2008-08-24 21:49:00 -04003287/**
James Smart3772a992009-05-22 14:50:54 -04003288 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
3289 * @phba: pointer to lpfc hba data structure.
3290 *
3291 * This routine is invoked to unset the PCI device memory space for device
3292 * with SLI-3 interface spec.
3293 **/
3294static void
3295lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
3296{
3297 struct pci_dev *pdev;
3298
3299 /* Obtain PCI device reference */
3300 if (!phba->pcidev)
3301 return;
3302 else
3303 pdev = phba->pcidev;
3304
3305 /* Free coherent DMA memory allocated */
3306 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
3307 phba->hbqslimp.virt, phba->hbqslimp.phys);
3308 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
3309 phba->slim2p.virt, phba->slim2p.phys);
3310
3311 /* I/O memory unmap */
3312 iounmap(phba->ctrl_regs_memmap_p);
3313 iounmap(phba->slim_memmap_p);
3314
3315 return;
3316}
3317
3318/**
3319 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
3320 * @phba: pointer to lpfc hba data structure.
3321 *
3322 * This routine is invoked to enable the MSI-X interrupt vectors to device
3323 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
3324 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
3325 * invoked, enables either all or nothing, depending on the current
3326 * availability of PCI vector resources. The device driver is responsible
3327 * for calling the individual request_irq() to register each MSI-X vector
3328 * with a interrupt handler, which is done in this function. Note that
3329 * later when device is unloading, the driver should always call free_irq()
3330 * on all MSI-X vectors it has done request_irq() on before calling
3331 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
3332 * will be left with MSI-X enabled and leaks its vectors.
3333 *
3334 * Return codes
3335 * 0 - sucessful
3336 * other values - error
3337 **/
3338static int
3339lpfc_sli_enable_msix(struct lpfc_hba *phba)
3340{
3341 int rc, i;
3342 LPFC_MBOXQ_t *pmb;
3343
3344 /* Set up MSI-X multi-message vectors */
3345 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
3346 phba->msix_entries[i].entry = i;
3347
3348 /* Configure MSI-X capability structure */
3349 rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
3350 ARRAY_SIZE(phba->msix_entries));
3351 if (rc) {
3352 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3353 "0420 PCI enable MSI-X failed (%d)\n", rc);
3354 goto msi_fail_out;
3355 }
3356 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
3357 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3358 "0477 MSI-X entry[%d]: vector=x%x "
3359 "message=%d\n", i,
3360 phba->msix_entries[i].vector,
3361 phba->msix_entries[i].entry);
3362 /*
3363 * Assign MSI-X vectors to interrupt handlers
3364 */
3365
3366 /* vector-0 is associated to slow-path handler */
3367 rc = request_irq(phba->msix_entries[0].vector,
3368 &lpfc_sli_sp_intr_handler, IRQF_SHARED,
3369 LPFC_SP_DRIVER_HANDLER_NAME, phba);
3370 if (rc) {
3371 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3372 "0421 MSI-X slow-path request_irq failed "
3373 "(%d)\n", rc);
3374 goto msi_fail_out;
3375 }
3376
3377 /* vector-1 is associated to fast-path handler */
3378 rc = request_irq(phba->msix_entries[1].vector,
3379 &lpfc_sli_fp_intr_handler, IRQF_SHARED,
3380 LPFC_FP_DRIVER_HANDLER_NAME, phba);
3381
3382 if (rc) {
3383 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3384 "0429 MSI-X fast-path request_irq failed "
3385 "(%d)\n", rc);
3386 goto irq_fail_out;
3387 }
3388
3389 /*
3390 * Configure HBA MSI-X attention conditions to messages
3391 */
3392 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3393
3394 if (!pmb) {
3395 rc = -ENOMEM;
3396 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3397 "0474 Unable to allocate memory for issuing "
3398 "MBOX_CONFIG_MSI command\n");
3399 goto mem_fail_out;
3400 }
3401 rc = lpfc_config_msi(phba, pmb);
3402 if (rc)
3403 goto mbx_fail_out;
3404 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3405 if (rc != MBX_SUCCESS) {
3406 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3407 "0351 Config MSI mailbox command failed, "
3408 "mbxCmd x%x, mbxStatus x%x\n",
3409 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
3410 goto mbx_fail_out;
3411 }
3412
3413 /* Free memory allocated for mailbox command */
3414 mempool_free(pmb, phba->mbox_mem_pool);
3415 return rc;
3416
3417mbx_fail_out:
3418 /* Free memory allocated for mailbox command */
3419 mempool_free(pmb, phba->mbox_mem_pool);
3420
3421mem_fail_out:
3422 /* free the irq already requested */
3423 free_irq(phba->msix_entries[1].vector, phba);
3424
3425irq_fail_out:
3426 /* free the irq already requested */
3427 free_irq(phba->msix_entries[0].vector, phba);
3428
3429msi_fail_out:
3430 /* Unconfigure MSI-X capability structure */
3431 pci_disable_msix(phba->pcidev);
3432 return rc;
3433}
3434
3435/**
3436 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
3437 * @phba: pointer to lpfc hba data structure.
3438 *
3439 * This routine is invoked to release the MSI-X vectors and then disable the
3440 * MSI-X interrupt mode to device with SLI-3 interface spec.
3441 **/
3442static void
3443lpfc_sli_disable_msix(struct lpfc_hba *phba)
3444{
3445 int i;
3446
3447 /* Free up MSI-X multi-message vectors */
3448 for (i = 0; i < LPFC_MSIX_VECTORS; i++)
3449 free_irq(phba->msix_entries[i].vector, phba);
3450 /* Disable MSI-X */
3451 pci_disable_msix(phba->pcidev);
3452
3453 return;
3454}
3455
3456/**
3457 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
3458 * @phba: pointer to lpfc hba data structure.
3459 *
3460 * This routine is invoked to enable the MSI interrupt mode to device with
3461 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
3462 * enable the MSI vector. The device driver is responsible for calling the
3463 * request_irq() to register MSI vector with a interrupt the handler, which
3464 * is done in this function.
3465 *
3466 * Return codes
3467 * 0 - sucessful
3468 * other values - error
3469 */
3470static int
3471lpfc_sli_enable_msi(struct lpfc_hba *phba)
3472{
3473 int rc;
3474
3475 rc = pci_enable_msi(phba->pcidev);
3476 if (!rc)
3477 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3478 "0462 PCI enable MSI mode success.\n");
3479 else {
3480 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3481 "0471 PCI enable MSI mode failed (%d)\n", rc);
3482 return rc;
3483 }
3484
3485 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
3486 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
3487 if (rc) {
3488 pci_disable_msi(phba->pcidev);
3489 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3490 "0478 MSI request_irq failed (%d)\n", rc);
3491 }
3492 return rc;
3493}
3494
3495/**
3496 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
3497 * @phba: pointer to lpfc hba data structure.
3498 *
3499 * This routine is invoked to disable the MSI interrupt mode to device with
3500 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
3501 * done request_irq() on before calling pci_disable_msi(). Failure to do so
3502 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
3503 * its vector.
3504 */
3505static void
3506lpfc_sli_disable_msi(struct lpfc_hba *phba)
3507{
3508 free_irq(phba->pcidev->irq, phba);
3509 pci_disable_msi(phba->pcidev);
3510 return;
3511}
3512
3513/**
3514 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
3515 * @phba: pointer to lpfc hba data structure.
3516 *
3517 * This routine is invoked to enable device interrupt and associate driver's
3518 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
3519 * spec. Depends on the interrupt mode configured to the driver, the driver
3520 * will try to fallback from the configured interrupt mode to an interrupt
3521 * mode which is supported by the platform, kernel, and device in the order
3522 * of:
3523 * MSI-X -> MSI -> IRQ.
3524 *
3525 * Return codes
3526 * 0 - sucessful
3527 * other values - error
3528 **/
3529static uint32_t
3530lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
3531{
3532 uint32_t intr_mode = LPFC_INTR_ERROR;
3533 int retval;
3534
3535 if (cfg_mode == 2) {
3536 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
3537 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
3538 if (!retval) {
3539 /* Now, try to enable MSI-X interrupt mode */
3540 retval = lpfc_sli_enable_msix(phba);
3541 if (!retval) {
3542 /* Indicate initialization to MSI-X mode */
3543 phba->intr_type = MSIX;
3544 intr_mode = 2;
3545 }
3546 }
3547 }
3548
3549 /* Fallback to MSI if MSI-X initialization failed */
3550 if (cfg_mode >= 1 && phba->intr_type == NONE) {
3551 retval = lpfc_sli_enable_msi(phba);
3552 if (!retval) {
3553 /* Indicate initialization to MSI mode */
3554 phba->intr_type = MSI;
3555 intr_mode = 1;
3556 }
3557 }
3558
3559 /* Fallback to INTx if both MSI-X/MSI initalization failed */
3560 if (phba->intr_type == NONE) {
3561 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
3562 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
3563 if (!retval) {
3564 /* Indicate initialization to INTx mode */
3565 phba->intr_type = INTx;
3566 intr_mode = 0;
3567 }
3568 }
3569 return intr_mode;
3570}
3571
3572/**
3573 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
3574 * @phba: pointer to lpfc hba data structure.
3575 *
3576 * This routine is invoked to disable device interrupt and disassociate the
3577 * driver's interrupt handler(s) from interrupt vector(s) to device with
3578 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
3579 * release the interrupt vector(s) for the message signaled interrupt.
3580 **/
3581static void
3582lpfc_sli_disable_intr(struct lpfc_hba *phba)
3583{
3584 /* Disable the currently initialized interrupt mode */
3585 if (phba->intr_type == MSIX)
3586 lpfc_sli_disable_msix(phba);
3587 else if (phba->intr_type == MSI)
3588 lpfc_sli_disable_msi(phba);
3589 else if (phba->intr_type == INTx)
3590 free_irq(phba->pcidev->irq, phba);
3591
3592 /* Reset interrupt management states */
3593 phba->intr_type = NONE;
3594 phba->sli.slistat.sli_intr = 0;
3595
3596 return;
3597}
3598
3599/**
3600 * lpfc_unset_hba - Unset SLI3 hba device initialization
3601 * @phba: pointer to lpfc hba data structure.
3602 *
3603 * This routine is invoked to unset the HBA device initialization steps to
3604 * a device with SLI-3 interface spec.
3605 **/
3606static void
3607lpfc_unset_hba(struct lpfc_hba *phba)
3608{
3609 struct lpfc_vport *vport = phba->pport;
3610 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3611
3612 spin_lock_irq(shost->host_lock);
3613 vport->load_flag |= FC_UNLOADING;
3614 spin_unlock_irq(shost->host_lock);
3615
3616 lpfc_stop_hba_timers(phba);
3617
3618 phba->pport->work_port_events = 0;
3619
3620 lpfc_sli_hba_down(phba);
3621
3622 lpfc_sli_brdrestart(phba);
3623
3624 lpfc_sli_disable_intr(phba);
3625
3626 return;
3627}
3628
3629/**
3630 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
3631 * @pdev: pointer to PCI device
3632 * @pid: pointer to PCI device identifier
3633 *
3634 * This routine is to be called to attach a device with SLI-3 interface spec
3635 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
3636 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
3637 * information of the device and driver to see if the driver state that it can
3638 * support this kind of device. If the match is successful, the driver core
3639 * invokes this routine. If this routine determines it can claim the HBA, it
3640 * does all the initialization that it needs to do to handle the HBA properly.
3641 *
3642 * Return code
3643 * 0 - driver can claim the device
3644 * negative value - driver can not claim the device
3645 **/
3646static int __devinit
3647lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
3648{
3649 struct lpfc_hba *phba;
3650 struct lpfc_vport *vport = NULL;
3651 int error;
3652 uint32_t cfg_mode, intr_mode;
3653
3654 /* Allocate memory for HBA structure */
3655 phba = lpfc_hba_alloc(pdev);
3656 if (!phba)
3657 return -ENOMEM;
3658
3659 /* Perform generic PCI device enabling operation */
3660 error = lpfc_enable_pci_dev(phba);
3661 if (error) {
3662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3663 "1401 Failed to enable pci device.\n");
3664 goto out_free_phba;
3665 }
3666
3667 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
3668 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
3669 if (error)
3670 goto out_disable_pci_dev;
3671
3672 /* Set up SLI-3 specific device PCI memory space */
3673 error = lpfc_sli_pci_mem_setup(phba);
3674 if (error) {
3675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3676 "1402 Failed to set up pci memory space.\n");
3677 goto out_disable_pci_dev;
3678 }
3679
3680 /* Set up phase-1 common device driver resources */
3681 error = lpfc_setup_driver_resource_phase1(phba);
3682 if (error) {
3683 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3684 "1403 Failed to set up driver resource.\n");
3685 goto out_unset_pci_mem_s3;
3686 }
3687
3688 /* Set up SLI-3 specific device driver resources */
3689 error = lpfc_sli_driver_resource_setup(phba);
3690 if (error) {
3691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3692 "1404 Failed to set up driver resource.\n");
3693 goto out_unset_pci_mem_s3;
3694 }
3695
3696 /* Initialize and populate the iocb list per host */
3697 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
3698 if (error) {
3699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3700 "1405 Failed to initialize iocb list.\n");
3701 goto out_unset_driver_resource_s3;
3702 }
3703
3704 /* Set up common device driver resources */
3705 error = lpfc_setup_driver_resource_phase2(phba);
3706 if (error) {
3707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3708 "1406 Failed to set up driver resource.\n");
3709 goto out_free_iocb_list;
3710 }
3711
3712 /* Create SCSI host to the physical port */
3713 error = lpfc_create_shost(phba);
3714 if (error) {
3715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3716 "1407 Failed to create scsi host.\n");
3717 goto out_unset_driver_resource;
3718 }
3719
3720 /* Configure sysfs attributes */
3721 vport = phba->pport;
3722 error = lpfc_alloc_sysfs_attr(vport);
3723 if (error) {
3724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3725 "1476 Failed to allocate sysfs attr\n");
3726 goto out_destroy_shost;
3727 }
3728
3729 /* Now, trying to enable interrupt and bring up the device */
3730 cfg_mode = phba->cfg_use_msi;
3731 while (true) {
3732 /* Put device to a known state before enabling interrupt */
3733 lpfc_stop_port(phba);
3734 /* Configure and enable interrupt */
3735 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
3736 if (intr_mode == LPFC_INTR_ERROR) {
3737 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3738 "0431 Failed to enable interrupt.\n");
3739 error = -ENODEV;
3740 goto out_free_sysfs_attr;
3741 }
3742 /* SLI-3 HBA setup */
3743 if (lpfc_sli_hba_setup(phba)) {
3744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3745 "1477 Failed to set up hba\n");
3746 error = -ENODEV;
3747 goto out_remove_device;
3748 }
3749
3750 /* Wait 50ms for the interrupts of previous mailbox commands */
3751 msleep(50);
3752 /* Check active interrupts on message signaled interrupts */
3753 if (intr_mode == 0 ||
3754 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
3755 /* Log the current active interrupt mode */
3756 phba->intr_mode = intr_mode;
3757 lpfc_log_intr_mode(phba, intr_mode);
3758 break;
3759 } else {
3760 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3761 "0447 Configure interrupt mode (%d) "
3762 "failed active interrupt test.\n",
3763 intr_mode);
3764 /* Disable the current interrupt mode */
3765 lpfc_sli_disable_intr(phba);
3766 /* Try next level of interrupt mode */
3767 cfg_mode = --intr_mode;
3768 }
3769 }
3770
3771 /* Perform post initialization setup */
3772 lpfc_post_init_setup(phba);
3773
3774 /* Check if there are static vports to be created. */
3775 lpfc_create_static_vport(phba);
3776
3777 return 0;
3778
3779out_remove_device:
3780 lpfc_unset_hba(phba);
3781out_free_sysfs_attr:
3782 lpfc_free_sysfs_attr(vport);
3783out_destroy_shost:
3784 lpfc_destroy_shost(phba);
3785out_unset_driver_resource:
3786 lpfc_unset_driver_resource_phase2(phba);
3787out_free_iocb_list:
3788 lpfc_free_iocb_list(phba);
3789out_unset_driver_resource_s3:
3790 lpfc_sli_driver_resource_unset(phba);
3791out_unset_pci_mem_s3:
3792 lpfc_sli_pci_mem_unset(phba);
3793out_disable_pci_dev:
3794 lpfc_disable_pci_dev(phba);
3795out_free_phba:
3796 lpfc_hba_free(phba);
3797 return error;
3798}
3799
3800/**
3801 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04003802 * @pdev: pointer to PCI device
3803 *
James Smart3772a992009-05-22 14:50:54 -04003804 * This routine is to be called to disattach a device with SLI-3 interface
3805 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
3806 * removed from PCI bus, it performs all the necessary cleanup for the HBA
3807 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04003808 **/
dea31012005-04-17 16:05:31 -05003809static void __devexit
James Smart3772a992009-05-22 14:50:54 -04003810lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05003811{
James Smart2e0fef82007-06-17 19:56:36 -05003812 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3813 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05003814 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05003815 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05003816 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003817 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
3818
James Smart549e55c2007-08-02 11:09:51 -04003819 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04003820 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04003821 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003822
James Smart858c9f62007-06-17 19:56:39 -05003823 lpfc_free_sysfs_attr(vport);
3824
James Smarteada2722008-12-04 22:39:13 -05003825 /* Release all the vports against this physical port */
3826 vports = lpfc_create_vport_work_array(phba);
3827 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -04003828 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
James Smarteada2722008-12-04 22:39:13 -05003829 fc_vport_terminate(vports[i]->fc_vport);
3830 lpfc_destroy_vport_work_array(phba, vports);
3831
3832 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05003833 fc_remove_host(shost);
3834 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04003835 lpfc_cleanup(vport);
3836
James Smart2e0fef82007-06-17 19:56:36 -05003837 /*
3838 * Bring down the SLI Layer. This step disable all interrupts,
3839 * clears the rings, discards all mailbox commands, and resets
3840 * the HBA.
3841 */
James Smarta257bf92009-04-06 18:48:10 -04003842
3843 /* HBA interrupt will be diabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05003844 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04003845 /* Stop kthread signal shall trigger work_done one more time */
3846 kthread_stop(phba->worker_thread);
3847 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05003848 lpfc_sli_brdrestart(phba);
3849
James Smart3772a992009-05-22 14:50:54 -04003850 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05003851 spin_lock_irq(&phba->hbalock);
3852 list_del_init(&vport->listentry);
3853 spin_unlock_irq(&phba->hbalock);
3854
James Smart858c9f62007-06-17 19:56:39 -05003855 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003856
James Smart5b75da22008-12-04 22:39:35 -05003857 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04003858 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05003859
3860 pci_set_drvdata(pdev, NULL);
James Smart858c9f62007-06-17 19:56:39 -05003861 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05003862
3863 /*
3864 * Call scsi_free before mem_free since scsi bufs are released to their
3865 * corresponding pools here.
3866 */
3867 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04003868 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003869
James Smart34b02dc2008-08-24 21:49:55 -04003870 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
3871 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05003872
James Smart2e0fef82007-06-17 19:56:36 -05003873 /* Free resources associated with SLI2 interface */
3874 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -04003875 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -05003876
3877 /* unmap adapter SLIM and Control Registers */
3878 iounmap(phba->ctrl_regs_memmap_p);
3879 iounmap(phba->slim_memmap_p);
3880
James Smart3772a992009-05-22 14:50:54 -04003881 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003882
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05003883 pci_release_selected_regions(pdev, bars);
James Smart2e0fef82007-06-17 19:56:36 -05003884 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -05003885}
3886
Linas Vepstas8d63f372007-02-14 14:28:36 -06003887/**
James Smart3772a992009-05-22 14:50:54 -04003888 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05003889 * @pdev: pointer to PCI device
3890 * @msg: power management message
3891 *
James Smart3772a992009-05-22 14:50:54 -04003892 * This routine is to be called from the kernel's PCI subsystem to support
3893 * system Power Management (PM) to device with SLI-3 interface spec. When
3894 * PM invokes this method, it quiesces the device by stopping the driver's
3895 * worker thread for the device, turning off device's interrupt and DMA,
3896 * and bring the device offline. Note that as the driver implements the
3897 * minimum PM requirements to a power-aware driver's PM support for the
3898 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
3899 * to the suspend() method call will be treated as SUSPEND and the driver will
3900 * fully reinitialize its device during resume() method call, the driver will
3901 * set device to PCI_D3hot state in PCI config space instead of setting it
3902 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -05003903 *
3904 * Return code
James Smart3772a992009-05-22 14:50:54 -04003905 * 0 - driver suspended the device
3906 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05003907 **/
3908static int
James Smart3772a992009-05-22 14:50:54 -04003909lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -05003910{
3911 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3912 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3913
3914 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3915 "0473 PCI device Power Management suspend.\n");
3916
3917 /* Bring down the device */
3918 lpfc_offline_prep(phba);
3919 lpfc_offline(phba);
3920 kthread_stop(phba->worker_thread);
3921
3922 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -04003923 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -05003924
3925 /* Save device state to PCI config space */
3926 pci_save_state(pdev);
3927 pci_set_power_state(pdev, PCI_D3hot);
3928
3929 return 0;
3930}
3931
3932/**
James Smart3772a992009-05-22 14:50:54 -04003933 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -05003934 * @pdev: pointer to PCI device
3935 *
James Smart3772a992009-05-22 14:50:54 -04003936 * This routine is to be called from the kernel's PCI subsystem to support
3937 * system Power Management (PM) to device with SLI-3 interface spec. When PM
3938 * invokes this method, it restores the device's PCI config space state and
3939 * fully reinitializes the device and brings it online. Note that as the
3940 * driver implements the minimum PM requirements to a power-aware driver's
3941 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
3942 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
3943 * driver will fully reinitialize its device during resume() method call,
3944 * the device will be set to PCI_D0 directly in PCI config space before
3945 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -05003946 *
3947 * Return code
James Smart3772a992009-05-22 14:50:54 -04003948 * 0 - driver suspended the device
3949 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -05003950 **/
3951static int
James Smart3772a992009-05-22 14:50:54 -04003952lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -05003953{
3954 struct Scsi_Host *shost = pci_get_drvdata(pdev);
3955 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -05003956 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003957 int error;
3958
3959 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3960 "0452 PCI device Power Management resume.\n");
3961
3962 /* Restore device state from PCI config space */
3963 pci_set_power_state(pdev, PCI_D0);
3964 pci_restore_state(pdev);
3965 if (pdev->is_busmaster)
3966 pci_set_master(pdev);
3967
3968 /* Startup the kernel thread for this host adapter. */
3969 phba->worker_thread = kthread_run(lpfc_do_work, phba,
3970 "lpfc_worker_%d", phba->brd_no);
3971 if (IS_ERR(phba->worker_thread)) {
3972 error = PTR_ERR(phba->worker_thread);
3973 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3974 "0434 PM resume failed to start worker "
3975 "thread: error=x%x.\n", error);
3976 return error;
3977 }
3978
James Smart5b75da22008-12-04 22:39:35 -05003979 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04003980 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05003981 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -05003982 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -05003983 "0430 PM resume Failed to enable interrupt\n");
3984 return -EIO;
3985 } else
3986 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -05003987
3988 /* Restart HBA and bring it online */
3989 lpfc_sli_brdrestart(phba);
3990 lpfc_online(phba);
3991
James Smart5b75da22008-12-04 22:39:35 -05003992 /* Log the current active interrupt mode */
3993 lpfc_log_intr_mode(phba, phba->intr_mode);
3994
James Smart3a55b532008-12-04 22:38:54 -05003995 return 0;
3996}
3997
3998/**
James Smart3772a992009-05-22 14:50:54 -04003999 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -04004000 * @pdev: pointer to PCI device.
4001 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -06004002 *
James Smart3772a992009-05-22 14:50:54 -04004003 * This routine is called from the PCI subsystem for I/O error handling to
4004 * device with SLI-3 interface spec. This function is called by the PCI
4005 * subsystem after a PCI bus error affecting this device has been detected.
4006 * When this function is invoked, it will need to stop all the I/Os and
4007 * interrupt(s) to the device. Once that is done, it will return
4008 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
4009 * as desired.
James Smarte59058c2008-08-24 21:49:00 -04004010 *
4011 * Return codes
James Smart3772a992009-05-22 14:50:54 -04004012 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
4013 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -04004014 **/
James Smart3772a992009-05-22 14:50:54 -04004015static pci_ers_result_t
4016lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -06004017{
James Smart51ef4c22007-08-02 11:10:31 -04004018 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4019 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06004020 struct lpfc_sli *psli = &phba->sli;
4021 struct lpfc_sli_ring *pring;
4022
James Smarta8e497d2008-08-24 21:50:11 -04004023 if (state == pci_channel_io_perm_failure) {
4024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4025 "0472 PCI channel I/O permanent failure\n");
4026 /* Block all SCSI devices' I/Os on the host */
4027 lpfc_scsi_dev_block(phba);
4028 /* Clean up all driver's outstanding SCSI I/Os */
4029 lpfc_sli_flush_fcp_rings(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06004030 return PCI_ERS_RESULT_DISCONNECT;
James Smarta8e497d2008-08-24 21:50:11 -04004031 }
Linas Vepstas5daa49e2007-03-08 16:19:11 -06004032
Linas Vepstas8d63f372007-02-14 14:28:36 -06004033 pci_disable_device(pdev);
4034 /*
4035 * There may be I/Os dropped by the firmware.
4036 * Error iocb (I/O) on txcmplq and let the SCSI layer
4037 * retry it after re-establishing link.
4038 */
4039 pring = &psli->ring[psli->fcp_ring];
4040 lpfc_sli_abort_iocb_ring(phba, pring);
4041
James Smart5b75da22008-12-04 22:39:35 -05004042 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04004043 lpfc_sli_disable_intr(phba);
James Smart51ef4c22007-08-02 11:10:31 -04004044
Linas Vepstas8d63f372007-02-14 14:28:36 -06004045 /* Request a slot reset. */
4046 return PCI_ERS_RESULT_NEED_RESET;
4047}
4048
4049/**
James Smart3772a992009-05-22 14:50:54 -04004050 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -04004051 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -06004052 *
James Smart3772a992009-05-22 14:50:54 -04004053 * This routine is called from the PCI subsystem for error handling to
4054 * device with SLI-3 interface spec. This is called after PCI bus has been
4055 * reset to restart the PCI card from scratch, as if from a cold-boot.
4056 * During the PCI subsystem error recovery, after driver returns
4057 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
4058 * recovery and then call this routine before calling the .resume method
4059 * to recover the device. This function will initialize the HBA device,
4060 * enable the interrupt, but it will just put the HBA to offline state
4061 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -04004062 *
4063 * Return codes
James Smart3772a992009-05-22 14:50:54 -04004064 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
4065 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -06004066 */
James Smart3772a992009-05-22 14:50:54 -04004067static pci_ers_result_t
4068lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06004069{
James Smart51ef4c22007-08-02 11:10:31 -04004070 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4071 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06004072 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -05004073 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06004074
4075 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11004076 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -06004077 printk(KERN_ERR "lpfc: Cannot re-enable "
4078 "PCI device after reset.\n");
4079 return PCI_ERS_RESULT_DISCONNECT;
4080 }
4081
James Smart97207482008-12-04 22:39:19 -05004082 pci_restore_state(pdev);
4083 if (pdev->is_busmaster)
4084 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -06004085
James Smart92d7f7b2007-06-17 19:56:38 -05004086 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -04004087 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05004088 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06004089
James Smart5b75da22008-12-04 22:39:35 -05004090 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -04004091 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -05004092 if (intr_mode == LPFC_INTR_ERROR) {
4093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4094 "0427 Cannot re-enable interrupt after "
4095 "slot reset.\n");
4096 return PCI_ERS_RESULT_DISCONNECT;
4097 } else
4098 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -06004099
4100 /* Take device offline; this will perform cleanup */
4101 lpfc_offline(phba);
4102 lpfc_sli_brdrestart(phba);
4103
James Smart5b75da22008-12-04 22:39:35 -05004104 /* Log the current active interrupt mode */
4105 lpfc_log_intr_mode(phba, phba->intr_mode);
4106
Linas Vepstas8d63f372007-02-14 14:28:36 -06004107 return PCI_ERS_RESULT_RECOVERED;
4108}
4109
4110/**
James Smart3772a992009-05-22 14:50:54 -04004111 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -04004112 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -06004113 *
James Smart3772a992009-05-22 14:50:54 -04004114 * This routine is called from the PCI subsystem for error handling to device
4115 * with SLI-3 interface spec. It is called when kernel error recovery tells
4116 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
4117 * error recovery. After this call, traffic can start to flow from this device
4118 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -06004119 */
James Smart3772a992009-05-22 14:50:54 -04004120static void
4121lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -06004122{
James Smart51ef4c22007-08-02 11:10:31 -04004123 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4124 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -06004125
James Smart58da1ff2008-04-07 10:15:56 -04004126 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -06004127}
4128
James Smart3772a992009-05-22 14:50:54 -04004129/**
4130 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
4131 * @pdev: pointer to PCI device
4132 * @pid: pointer to PCI device identifier
4133 *
4134 * This routine is to be registered to the kernel's PCI subsystem. When an
4135 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
4136 * at PCI device-specific information of the device and driver to see if the
4137 * driver state that it can support this kind of device. If the match is
4138 * successful, the driver core invokes this routine. This routine dispatches
4139 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
4140 * do all the initialization that it needs to do to handle the HBA device
4141 * properly.
4142 *
4143 * Return code
4144 * 0 - driver can claim the device
4145 * negative value - driver can not claim the device
4146 **/
4147static int __devinit
4148lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
4149{
4150 int rc;
4151 uint16_t dev_id;
4152
4153 if (pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id))
4154 return -ENODEV;
4155
4156 switch (dev_id) {
4157 default:
4158 rc = lpfc_pci_probe_one_s3(pdev, pid);
4159 break;
4160 }
4161 return rc;
4162}
4163
4164/**
4165 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
4166 * @pdev: pointer to PCI device
4167 *
4168 * This routine is to be registered to the kernel's PCI subsystem. When an
4169 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
4170 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
4171 * remove routine, which will perform all the necessary cleanup for the
4172 * device to be removed from the PCI subsystem properly.
4173 **/
4174static void __devexit
4175lpfc_pci_remove_one(struct pci_dev *pdev)
4176{
4177 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4178 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4179
4180 switch (phba->pci_dev_grp) {
4181 case LPFC_PCI_DEV_LP:
4182 lpfc_pci_remove_one_s3(pdev);
4183 break;
4184 default:
4185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4186 "1424 Invalid PCI device group: 0x%x\n",
4187 phba->pci_dev_grp);
4188 break;
4189 }
4190 return;
4191}
4192
4193/**
4194 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
4195 * @pdev: pointer to PCI device
4196 * @msg: power management message
4197 *
4198 * This routine is to be registered to the kernel's PCI subsystem to support
4199 * system Power Management (PM). When PM invokes this method, it dispatches
4200 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
4201 * suspend the device.
4202 *
4203 * Return code
4204 * 0 - driver suspended the device
4205 * Error otherwise
4206 **/
4207static int
4208lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
4209{
4210 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4211 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4212 int rc = -ENODEV;
4213
4214 switch (phba->pci_dev_grp) {
4215 case LPFC_PCI_DEV_LP:
4216 rc = lpfc_pci_suspend_one_s3(pdev, msg);
4217 break;
4218 default:
4219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4220 "1425 Invalid PCI device group: 0x%x\n",
4221 phba->pci_dev_grp);
4222 break;
4223 }
4224 return rc;
4225}
4226
4227/**
4228 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
4229 * @pdev: pointer to PCI device
4230 *
4231 * This routine is to be registered to the kernel's PCI subsystem to support
4232 * system Power Management (PM). When PM invokes this method, it dispatches
4233 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
4234 * resume the device.
4235 *
4236 * Return code
4237 * 0 - driver suspended the device
4238 * Error otherwise
4239 **/
4240static int
4241lpfc_pci_resume_one(struct pci_dev *pdev)
4242{
4243 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4244 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4245 int rc = -ENODEV;
4246
4247 switch (phba->pci_dev_grp) {
4248 case LPFC_PCI_DEV_LP:
4249 rc = lpfc_pci_resume_one_s3(pdev);
4250 break;
4251 default:
4252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4253 "1426 Invalid PCI device group: 0x%x\n",
4254 phba->pci_dev_grp);
4255 break;
4256 }
4257 return rc;
4258}
4259
4260/**
4261 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
4262 * @pdev: pointer to PCI device.
4263 * @state: the current PCI connection state.
4264 *
4265 * This routine is registered to the PCI subsystem for error handling. This
4266 * function is called by the PCI subsystem after a PCI bus error affecting
4267 * this device has been detected. When this routine is invoked, it dispatches
4268 * the action to the proper SLI-3 or SLI-4 device error detected handling
4269 * routine, which will perform the proper error detected operation.
4270 *
4271 * Return codes
4272 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
4273 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
4274 **/
4275static pci_ers_result_t
4276lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4277{
4278 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4279 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4280 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
4281
4282 switch (phba->pci_dev_grp) {
4283 case LPFC_PCI_DEV_LP:
4284 rc = lpfc_io_error_detected_s3(pdev, state);
4285 break;
4286 default:
4287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4288 "1427 Invalid PCI device group: 0x%x\n",
4289 phba->pci_dev_grp);
4290 break;
4291 }
4292 return rc;
4293}
4294
4295/**
4296 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
4297 * @pdev: pointer to PCI device.
4298 *
4299 * This routine is registered to the PCI subsystem for error handling. This
4300 * function is called after PCI bus has been reset to restart the PCI card
4301 * from scratch, as if from a cold-boot. When this routine is invoked, it
4302 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
4303 * routine, which will perform the proper device reset.
4304 *
4305 * Return codes
4306 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
4307 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
4308 **/
4309static pci_ers_result_t
4310lpfc_io_slot_reset(struct pci_dev *pdev)
4311{
4312 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4313 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4314 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
4315
4316 switch (phba->pci_dev_grp) {
4317 case LPFC_PCI_DEV_LP:
4318 rc = lpfc_io_slot_reset_s3(pdev);
4319 break;
4320 default:
4321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4322 "1428 Invalid PCI device group: 0x%x\n",
4323 phba->pci_dev_grp);
4324 break;
4325 }
4326 return rc;
4327}
4328
4329/**
4330 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
4331 * @pdev: pointer to PCI device
4332 *
4333 * This routine is registered to the PCI subsystem for error handling. It
4334 * is called when kernel error recovery tells the lpfc driver that it is
4335 * OK to resume normal PCI operation after PCI bus error recovery. When
4336 * this routine is invoked, it dispatches the action to the proper SLI-3
4337 * or SLI-4 device io_resume routine, which will resume the device operation.
4338 **/
4339static void
4340lpfc_io_resume(struct pci_dev *pdev)
4341{
4342 struct Scsi_Host *shost = pci_get_drvdata(pdev);
4343 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
4344
4345 switch (phba->pci_dev_grp) {
4346 case LPFC_PCI_DEV_LP:
4347 lpfc_io_resume_s3(pdev);
4348 break;
4349 default:
4350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4351 "1429 Invalid PCI device group: 0x%x\n",
4352 phba->pci_dev_grp);
4353 break;
4354 }
4355 return;
4356}
4357
dea31012005-04-17 16:05:31 -05004358static struct pci_device_id lpfc_id_table[] = {
4359 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
4360 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04004361 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
4362 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05004363 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
4364 PCI_ANY_ID, PCI_ANY_ID, },
4365 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
4366 PCI_ANY_ID, PCI_ANY_ID, },
4367 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
4368 PCI_ANY_ID, PCI_ANY_ID, },
4369 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
4370 PCI_ANY_ID, PCI_ANY_ID, },
4371 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
4372 PCI_ANY_ID, PCI_ANY_ID, },
4373 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
4374 PCI_ANY_ID, PCI_ANY_ID, },
4375 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
4376 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05004377 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
4378 PCI_ANY_ID, PCI_ANY_ID, },
4379 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
4380 PCI_ANY_ID, PCI_ANY_ID, },
4381 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
4382 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05004383 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
4384 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05004385 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
4386 PCI_ANY_ID, PCI_ANY_ID, },
4387 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
4388 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05004389 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
4390 PCI_ANY_ID, PCI_ANY_ID, },
4391 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
4392 PCI_ANY_ID, PCI_ANY_ID, },
4393 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
4394 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04004395 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
4396 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05004397 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
4398 PCI_ANY_ID, PCI_ANY_ID, },
4399 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
4400 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05004401 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
4402 PCI_ANY_ID, PCI_ANY_ID, },
4403 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
4404 PCI_ANY_ID, PCI_ANY_ID, },
4405 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
4406 PCI_ANY_ID, PCI_ANY_ID, },
4407 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
4408 PCI_ANY_ID, PCI_ANY_ID, },
4409 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
4410 PCI_ANY_ID, PCI_ANY_ID, },
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05004411 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
4412 PCI_ANY_ID, PCI_ANY_ID, },
4413 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
4414 PCI_ANY_ID, PCI_ANY_ID, },
James Smartb87eab32007-04-25 09:53:28 -04004415 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
4416 PCI_ANY_ID, PCI_ANY_ID, },
4417 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
4418 PCI_ANY_ID, PCI_ANY_ID, },
4419 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
4420 PCI_ANY_ID, PCI_ANY_ID, },
4421 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
4422 PCI_ANY_ID, PCI_ANY_ID, },
4423 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
4424 PCI_ANY_ID, PCI_ANY_ID, },
4425 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
4426 PCI_ANY_ID, PCI_ANY_ID, },
James Smart84774a42008-08-24 21:50:06 -04004427 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
4428 PCI_ANY_ID, PCI_ANY_ID, },
4429 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
4430 PCI_ANY_ID, PCI_ANY_ID, },
4431 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
4432 PCI_ANY_ID, PCI_ANY_ID, },
James Smart3772a992009-05-22 14:50:54 -04004433 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
4434 PCI_ANY_ID, PCI_ANY_ID, },
4435 {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK_S,
4436 PCI_ANY_ID, PCI_ANY_ID, },
dea31012005-04-17 16:05:31 -05004437 { 0 }
4438};
4439
4440MODULE_DEVICE_TABLE(pci, lpfc_id_table);
4441
Linas Vepstas8d63f372007-02-14 14:28:36 -06004442static struct pci_error_handlers lpfc_err_handler = {
4443 .error_detected = lpfc_io_error_detected,
4444 .slot_reset = lpfc_io_slot_reset,
4445 .resume = lpfc_io_resume,
4446};
4447
dea31012005-04-17 16:05:31 -05004448static struct pci_driver lpfc_driver = {
4449 .name = LPFC_DRIVER_NAME,
4450 .id_table = lpfc_id_table,
4451 .probe = lpfc_pci_probe_one,
4452 .remove = __devexit_p(lpfc_pci_remove_one),
James Smart3a55b532008-12-04 22:38:54 -05004453 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -04004454 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -05004455 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -05004456};
4457
James Smarte59058c2008-08-24 21:49:00 -04004458/**
James Smart3621a712009-04-06 18:47:14 -04004459 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -04004460 *
4461 * This routine is to be invoked when the lpfc module is loaded into the
4462 * kernel. The special kernel macro module_init() is used to indicate the
4463 * role of this routine to the kernel as lpfc module entry point.
4464 *
4465 * Return codes
4466 * 0 - successful
4467 * -ENOMEM - FC attach transport failed
4468 * all others - failed
4469 */
dea31012005-04-17 16:05:31 -05004470static int __init
4471lpfc_init(void)
4472{
4473 int error = 0;
4474
4475 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04004476 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -05004477
James Smart7ee5d432007-10-27 13:37:17 -04004478 if (lpfc_enable_npiv) {
4479 lpfc_transport_functions.vport_create = lpfc_vport_create;
4480 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
4481 }
dea31012005-04-17 16:05:31 -05004482 lpfc_transport_template =
4483 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -04004484 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -05004485 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -04004486 if (lpfc_enable_npiv) {
James Smart7ee5d432007-10-27 13:37:17 -04004487 lpfc_vport_transport_template =
James Smart98c9ea52007-10-27 13:37:33 -04004488 fc_attach_transport(&lpfc_vport_transport_functions);
4489 if (lpfc_vport_transport_template == NULL) {
4490 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04004491 return -ENOMEM;
James Smart98c9ea52007-10-27 13:37:33 -04004492 }
James Smart7ee5d432007-10-27 13:37:17 -04004493 }
dea31012005-04-17 16:05:31 -05004494 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -05004495 if (error) {
dea31012005-04-17 16:05:31 -05004496 fc_release_transport(lpfc_transport_template);
James Smartd7c255b2008-08-24 21:50:00 -04004497 if (lpfc_enable_npiv)
4498 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -05004499 }
dea31012005-04-17 16:05:31 -05004500
4501 return error;
4502}
4503
James Smarte59058c2008-08-24 21:49:00 -04004504/**
James Smart3621a712009-04-06 18:47:14 -04004505 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -04004506 *
4507 * This routine is invoked when the lpfc module is removed from the kernel.
4508 * The special kernel macro module_exit() is used to indicate the role of
4509 * this routine to the kernel as lpfc module exit point.
4510 */
dea31012005-04-17 16:05:31 -05004511static void __exit
4512lpfc_exit(void)
4513{
4514 pci_unregister_driver(&lpfc_driver);
4515 fc_release_transport(lpfc_transport_template);
James Smart7ee5d432007-10-27 13:37:17 -04004516 if (lpfc_enable_npiv)
4517 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -05004518 if (_dump_buf_data) {
4519 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data "
4520 "at 0x%p\n",
4521 (1L << _dump_buf_data_order), _dump_buf_data);
4522 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
4523 }
4524
4525 if (_dump_buf_dif) {
4526 printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif "
4527 "at 0x%p\n",
4528 (1L << _dump_buf_dif_order), _dump_buf_dif);
4529 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
4530 }
dea31012005-04-17 16:05:31 -05004531}
4532
4533module_init(lpfc_init);
4534module_exit(lpfc_exit);
4535MODULE_LICENSE("GPL");
4536MODULE_DESCRIPTION(LPFC_MODULE_DESC);
4537MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
4538MODULE_VERSION("0:" LPFC_DRIVER_VERSION);