1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * 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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_version.h"
47 static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
48 static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
49 static int lpfc_post_rcv_buf(struct lpfc_hba *);
51 static struct scsi_transport_template *lpfc_transport_template = NULL;
52 static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
53 static DEFINE_IDR(lpfc_hba_index);
56 * lpfc_config_port_prep: Perform lpfc initialization prior to config port.
57 * @phba: pointer to lpfc hba data structure.
59 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
60 * mailbox command. It retrieves the revision information from the HBA and
61 * collects the Vital Product Data (VPD) about the HBA for preparing the
62 * configuration of the HBA.
66 * -ERESTART - requests the SLI layer to reset the HBA and try again.
67 * Any other value - indicates an error.
70 lpfc_config_port_prep(struct lpfc_hba *phba)
72 lpfc_vpd_t *vp = &phba->vpd;
76 char *lpfc_vpd_data = NULL;
78 static char licensed[56] =
79 "key unlock for use with gnu public licensed code only\0";
80 static int init_key = 1;
82 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
84 phba->link_state = LPFC_HBA_ERROR;
89 phba->link_state = LPFC_INIT_MBX_CMDS;
91 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
93 uint32_t *ptext = (uint32_t *) licensed;
95 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
96 *ptext = cpu_to_be32(*ptext);
100 lpfc_read_nv(phba, pmb);
101 memset((char*)mb->un.varRDnvp.rsvd3, 0,
102 sizeof (mb->un.varRDnvp.rsvd3));
103 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
106 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
108 if (rc != MBX_SUCCESS) {
109 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
110 "0324 Config Port initialization "
111 "error, mbxCmd x%x READ_NVPARM, "
113 mb->mbxCommand, mb->mbxStatus);
114 mempool_free(pmb, phba->mbox_mem_pool);
117 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
119 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
123 phba->sli3_options = 0x0;
125 /* Setup and issue mailbox READ REV command */
126 lpfc_read_rev(phba, pmb);
127 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
128 if (rc != MBX_SUCCESS) {
129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
130 "0439 Adapter failed to init, mbxCmd x%x "
131 "READ_REV, mbxStatus x%x\n",
132 mb->mbxCommand, mb->mbxStatus);
133 mempool_free( pmb, phba->mbox_mem_pool);
139 * The value of rr must be 1 since the driver set the cv field to 1.
140 * This setting requires the FW to set all revision fields.
142 if (mb->un.varRdRev.rr == 0) {
144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
145 "0440 Adapter failed to init, READ_REV has "
146 "missing revision information.\n");
147 mempool_free(pmb, phba->mbox_mem_pool);
151 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
152 mempool_free(pmb, phba->mbox_mem_pool);
156 /* Save information as VPD data */
158 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
159 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
160 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
161 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
162 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
163 vp->rev.biuRev = mb->un.varRdRev.biuRev;
164 vp->rev.smRev = mb->un.varRdRev.smRev;
165 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
166 vp->rev.endecRev = mb->un.varRdRev.endecRev;
167 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
168 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
169 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
170 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
171 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
172 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
174 /* If the sli feature level is less then 9, we must
175 * tear down all RPIs and VPIs on link down if NPIV
178 if (vp->rev.feaLevelHigh < 9)
179 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
181 if (lpfc_is_LC_HBA(phba->pcidev->device))
182 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
183 sizeof (phba->RandomData));
185 /* Get adapter VPD information */
186 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
191 lpfc_dump_mem(phba, pmb, offset);
192 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
194 if (rc != MBX_SUCCESS) {
195 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
196 "0441 VPD not present on adapter, "
197 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
198 mb->mbxCommand, mb->mbxStatus);
199 mb->un.varDmp.word_cnt = 0;
201 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
202 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
203 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
204 lpfc_vpd_data + offset,
205 mb->un.varDmp.word_cnt);
206 offset += mb->un.varDmp.word_cnt;
207 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
208 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
210 kfree(lpfc_vpd_data);
212 mempool_free(pmb, phba->mbox_mem_pool);
217 * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd.
218 * @phba: pointer to lpfc hba data structure.
219 * @pmboxq: pointer to the driver internal queue element for mailbox command.
221 * This is the completion handler for driver's configuring asynchronous event
222 * mailbox command to the device. If the mailbox command returns successfully,
223 * it will set internal async event support flag to 1; otherwise, it will
224 * set internal async event support flag to 0.
227 lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
229 if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
230 phba->temp_sensor_support = 1;
232 phba->temp_sensor_support = 0;
233 mempool_free(pmboxq, phba->mbox_mem_pool);
238 * lpfc_config_port_post: Perform lpfc initialization after config port.
239 * @phba: pointer to lpfc hba data structure.
241 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
242 * command call. It performs all internal resource and state setups on the
243 * port: post IOCB buffers, enable appropriate host interrupt attentions,
244 * ELS ring timers, etc.
248 * Any other value - error.
251 lpfc_config_port_post(struct lpfc_hba *phba)
253 struct lpfc_vport *vport = phba->pport;
256 struct lpfc_dmabuf *mp;
257 struct lpfc_sli *psli = &phba->sli;
258 uint32_t status, timeout;
262 spin_lock_irq(&phba->hbalock);
264 * If the Config port completed correctly the HBA is not
265 * over heated any more.
267 if (phba->over_temp_state == HBA_OVER_TEMP)
268 phba->over_temp_state = HBA_NORMAL_TEMP;
269 spin_unlock_irq(&phba->hbalock);
271 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
273 phba->link_state = LPFC_HBA_ERROR;
278 /* Get login parameters for NID. */
279 lpfc_read_sparam(phba, pmb, 0);
281 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
283 "0448 Adapter failed init, mbxCmd x%x "
284 "READ_SPARM mbxStatus x%x\n",
285 mb->mbxCommand, mb->mbxStatus);
286 phba->link_state = LPFC_HBA_ERROR;
287 mp = (struct lpfc_dmabuf *) pmb->context1;
288 mempool_free( pmb, phba->mbox_mem_pool);
289 lpfc_mbuf_free(phba, mp->virt, mp->phys);
294 mp = (struct lpfc_dmabuf *) pmb->context1;
296 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
297 lpfc_mbuf_free(phba, mp->virt, mp->phys);
299 pmb->context1 = NULL;
301 if (phba->cfg_soft_wwnn)
302 u64_to_wwn(phba->cfg_soft_wwnn,
303 vport->fc_sparam.nodeName.u.wwn);
304 if (phba->cfg_soft_wwpn)
305 u64_to_wwn(phba->cfg_soft_wwpn,
306 vport->fc_sparam.portName.u.wwn);
307 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
308 sizeof (struct lpfc_name));
309 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
310 sizeof (struct lpfc_name));
311 /* If no serial number in VPD data, use low 6 bytes of WWNN */
312 /* This should be consolidated into parse_vpd ? - mr */
313 if (phba->SerialNumber[0] == 0) {
316 outptr = &vport->fc_nodename.u.s.IEEE[0];
317 for (i = 0; i < 12; i++) {
319 j = ((status & 0xf0) >> 4);
321 phba->SerialNumber[i] =
322 (char)((uint8_t) 0x30 + (uint8_t) j);
324 phba->SerialNumber[i] =
325 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
329 phba->SerialNumber[i] =
330 (char)((uint8_t) 0x30 + (uint8_t) j);
332 phba->SerialNumber[i] =
333 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
337 lpfc_read_config(phba, pmb);
339 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
341 "0453 Adapter failed to init, mbxCmd x%x "
342 "READ_CONFIG, mbxStatus x%x\n",
343 mb->mbxCommand, mb->mbxStatus);
344 phba->link_state = LPFC_HBA_ERROR;
345 mempool_free( pmb, phba->mbox_mem_pool);
349 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
350 if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
351 phba->cfg_hba_queue_depth =
352 mb->un.varRdConfig.max_xri + 1;
354 phba->lmt = mb->un.varRdConfig.lmt;
356 /* Get the default values for Model Name and Description */
357 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
359 if ((phba->cfg_link_speed > LINK_SPEED_10G)
360 || ((phba->cfg_link_speed == LINK_SPEED_1G)
361 && !(phba->lmt & LMT_1Gb))
362 || ((phba->cfg_link_speed == LINK_SPEED_2G)
363 && !(phba->lmt & LMT_2Gb))
364 || ((phba->cfg_link_speed == LINK_SPEED_4G)
365 && !(phba->lmt & LMT_4Gb))
366 || ((phba->cfg_link_speed == LINK_SPEED_8G)
367 && !(phba->lmt & LMT_8Gb))
368 || ((phba->cfg_link_speed == LINK_SPEED_10G)
369 && !(phba->lmt & LMT_10Gb))) {
370 /* Reset link speed to auto */
371 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
372 "1302 Invalid speed for this board: "
373 "Reset link speed to auto: x%x\n",
374 phba->cfg_link_speed);
375 phba->cfg_link_speed = LINK_SPEED_AUTO;
378 phba->link_state = LPFC_LINK_DOWN;
380 /* Only process IOCBs on ELS ring till hba_state is READY */
381 if (psli->ring[psli->extra_ring].cmdringaddr)
382 psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
383 if (psli->ring[psli->fcp_ring].cmdringaddr)
384 psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
385 if (psli->ring[psli->next_ring].cmdringaddr)
386 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
388 /* Post receive buffers for desired rings */
389 if (phba->sli_rev != 3)
390 lpfc_post_rcv_buf(phba);
392 /* Enable appropriate host interrupts */
393 spin_lock_irq(&phba->hbalock);
394 status = readl(phba->HCregaddr);
395 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
396 if (psli->num_rings > 0)
397 status |= HC_R0INT_ENA;
398 if (psli->num_rings > 1)
399 status |= HC_R1INT_ENA;
400 if (psli->num_rings > 2)
401 status |= HC_R2INT_ENA;
402 if (psli->num_rings > 3)
403 status |= HC_R3INT_ENA;
405 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
406 (phba->cfg_poll & DISABLE_FCP_RING_INT))
407 status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
409 writel(status, phba->HCregaddr);
410 readl(phba->HCregaddr); /* flush */
411 spin_unlock_irq(&phba->hbalock);
414 * Setup the ring 0 (els) timeout handler
416 timeout = phba->fc_ratov << 1;
417 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
418 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
419 phba->hb_outstanding = 0;
420 phba->last_completion_time = jiffies;
422 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
423 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
424 lpfc_set_loopback_flag(phba);
425 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
426 if (rc != MBX_SUCCESS) {
427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
428 "0454 Adapter failed to init, mbxCmd x%x "
429 "INIT_LINK, mbxStatus x%x\n",
430 mb->mbxCommand, mb->mbxStatus);
432 /* Clear all interrupt enable conditions */
433 writel(0, phba->HCregaddr);
434 readl(phba->HCregaddr); /* flush */
435 /* Clear all pending interrupts */
436 writel(0xffffffff, phba->HAregaddr);
437 readl(phba->HAregaddr); /* flush */
439 phba->link_state = LPFC_HBA_ERROR;
441 mempool_free(pmb, phba->mbox_mem_pool);
444 /* MBOX buffer will be freed in mbox compl */
445 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
446 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
447 pmb->mbox_cmpl = lpfc_config_async_cmpl;
448 pmb->vport = phba->pport;
449 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
451 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
452 lpfc_printf_log(phba,
455 "0456 Adapter failed to issue "
456 "ASYNCEVT_ENABLE mbox status x%x \n.",
458 mempool_free(pmb, phba->mbox_mem_pool);
464 * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset.
465 * @phba: pointer to lpfc HBA data structure.
467 * This routine will do LPFC uninitialization before the HBA is reset when
468 * bringing down the SLI Layer.
472 * Any other value - error.
475 lpfc_hba_down_prep(struct lpfc_hba *phba)
477 struct lpfc_vport **vports;
479 /* Disable interrupts */
480 writel(0, phba->HCregaddr);
481 readl(phba->HCregaddr); /* flush */
483 if (phba->pport->load_flag & FC_UNLOADING)
484 lpfc_cleanup_discovery_resources(phba->pport);
486 vports = lpfc_create_vport_work_array(phba);
488 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
489 lpfc_cleanup_discovery_resources(vports[i]);
490 lpfc_destroy_vport_work_array(phba, vports);
496 * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset.
497 * @phba: pointer to lpfc HBA data structure.
499 * This routine will do uninitialization after the HBA is reset when bring
500 * down the SLI Layer.
504 * Any other value - error.
507 lpfc_hba_down_post(struct lpfc_hba *phba)
509 struct lpfc_sli *psli = &phba->sli;
510 struct lpfc_sli_ring *pring;
511 struct lpfc_dmabuf *mp, *next_mp;
512 struct lpfc_iocbq *iocb;
514 LIST_HEAD(completions);
517 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
518 lpfc_sli_hbqbuf_free_all(phba);
520 /* Cleanup preposted buffers on the ELS ring */
521 pring = &psli->ring[LPFC_ELS_RING];
522 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
524 pring->postbufq_cnt--;
525 lpfc_mbuf_free(phba, mp->virt, mp->phys);
530 spin_lock_irq(&phba->hbalock);
531 for (i = 0; i < psli->num_rings; i++) {
532 pring = &psli->ring[i];
534 /* At this point in time the HBA is either reset or DOA. Either
535 * way, nothing should be on txcmplq as it will NEVER complete.
537 list_splice_init(&pring->txcmplq, &completions);
538 pring->txcmplq_cnt = 0;
539 spin_unlock_irq(&phba->hbalock);
541 while (!list_empty(&completions)) {
542 iocb = list_get_first(&completions, struct lpfc_iocbq,
545 list_del_init(&iocb->list);
547 if (!iocb->iocb_cmpl)
548 lpfc_sli_release_iocbq(phba, iocb);
550 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
551 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
552 (iocb->iocb_cmpl) (phba, iocb, iocb);
556 lpfc_sli_abort_iocb_ring(phba, pring);
557 spin_lock_irq(&phba->hbalock);
559 spin_unlock_irq(&phba->hbalock);
565 * lpfc_hb_timeout: The HBA-timer timeout handler.
566 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
568 * This is the HBA-timer timeout handler registered to the lpfc driver. When
569 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
570 * work-port-events bitmap and the worker thread is notified. This timeout
571 * event will be used by the worker thread to invoke the actual timeout
572 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
573 * be performed in the timeout handler and the HBA timeout event bit shall
574 * be cleared by the worker thread after it has taken the event bitmap out.
577 lpfc_hb_timeout(unsigned long ptr)
579 struct lpfc_hba *phba;
583 phba = (struct lpfc_hba *)ptr;
584 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
585 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
587 phba->pport->work_port_events |= WORKER_HB_TMO;
588 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
591 lpfc_worker_wake_up(phba);
596 * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function.
597 * @phba: pointer to lpfc hba data structure.
598 * @pmboxq: pointer to the driver internal queue element for mailbox command.
600 * This is the callback function to the lpfc heart-beat mailbox command.
601 * If configured, the lpfc driver issues the heart-beat mailbox command to
602 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
603 * heart-beat mailbox command is issued, the driver shall set up heart-beat
604 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
605 * heart-beat outstanding state. Once the mailbox command comes back and
606 * no error conditions detected, the heart-beat mailbox command timer is
607 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
608 * state is cleared for the next heart-beat. If the timer expired with the
609 * heart-beat outstanding state set, the driver will put the HBA offline.
612 lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
614 unsigned long drvr_flag;
616 spin_lock_irqsave(&phba->hbalock, drvr_flag);
617 phba->hb_outstanding = 0;
618 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
620 mempool_free(pmboxq, phba->mbox_mem_pool);
621 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
622 !(phba->link_state == LPFC_HBA_ERROR) &&
623 !(phba->pport->load_flag & FC_UNLOADING))
624 mod_timer(&phba->hb_tmofunc,
625 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
630 * lpfc_hb_timeout_handler: The HBA-timer timeout handler.
631 * @phba: pointer to lpfc hba data structure.
633 * This is the actual HBA-timer timeout handler to be invoked by the worker
634 * thread whenever the HBA timer fired and HBA-timeout event posted. This
635 * handler performs any periodic operations needed for the device. If such
636 * periodic event has already been attended to either in the interrupt handler
637 * or by processing slow-ring or fast-ring events within the HBA-timer
638 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
639 * the timer for the next timeout period. If lpfc heart-beat mailbox command
640 * is configured and there is no heart-beat mailbox command outstanding, a
641 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
642 * has been a heart-beat mailbox command outstanding, the HBA shall be put
646 lpfc_hb_timeout_handler(struct lpfc_hba *phba)
648 LPFC_MBOXQ_t *pmboxq;
649 struct lpfc_dmabuf *buf_ptr;
651 struct lpfc_sli *psli = &phba->sli;
652 LIST_HEAD(completions);
654 if ((phba->link_state == LPFC_HBA_ERROR) ||
655 (phba->pport->load_flag & FC_UNLOADING) ||
656 (phba->pport->fc_flag & FC_OFFLINE_MODE))
659 spin_lock_irq(&phba->pport->work_port_lock);
660 /* If the timer is already canceled do nothing */
661 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
662 spin_unlock_irq(&phba->pport->work_port_lock);
666 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
668 spin_unlock_irq(&phba->pport->work_port_lock);
669 if (!phba->hb_outstanding)
670 mod_timer(&phba->hb_tmofunc,
671 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
673 mod_timer(&phba->hb_tmofunc,
674 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
677 spin_unlock_irq(&phba->pport->work_port_lock);
679 if (phba->elsbuf_cnt &&
680 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
681 spin_lock_irq(&phba->hbalock);
682 list_splice_init(&phba->elsbuf, &completions);
683 phba->elsbuf_cnt = 0;
684 phba->elsbuf_prev_cnt = 0;
685 spin_unlock_irq(&phba->hbalock);
687 while (!list_empty(&completions)) {
688 list_remove_head(&completions, buf_ptr,
689 struct lpfc_dmabuf, list);
690 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
694 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
696 /* If there is no heart beat outstanding, issue a heartbeat command */
697 if (phba->cfg_enable_hba_heartbeat) {
698 if (!phba->hb_outstanding) {
699 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
701 mod_timer(&phba->hb_tmofunc,
702 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
706 lpfc_heart_beat(phba, pmboxq);
707 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
708 pmboxq->vport = phba->pport;
709 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
711 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
712 mempool_free(pmboxq, phba->mbox_mem_pool);
713 mod_timer(&phba->hb_tmofunc,
714 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
717 mod_timer(&phba->hb_tmofunc,
718 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
719 phba->hb_outstanding = 1;
723 * If heart beat timeout called with hb_outstanding set
724 * we need to take the HBA offline.
726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
727 "0459 Adapter heartbeat failure, "
728 "taking this port offline.\n");
730 spin_lock_irq(&phba->hbalock);
731 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
732 spin_unlock_irq(&phba->hbalock);
734 lpfc_offline_prep(phba);
736 lpfc_unblock_mgmt_io(phba);
737 phba->link_state = LPFC_HBA_ERROR;
738 lpfc_hba_down_post(phba);
744 * lpfc_offline_eratt: Bring lpfc offline on hardware error attention.
745 * @phba: pointer to lpfc hba data structure.
747 * This routine is called to bring the HBA offline when HBA hardware error
748 * other than Port Error 6 has been detected.
751 lpfc_offline_eratt(struct lpfc_hba *phba)
753 struct lpfc_sli *psli = &phba->sli;
755 spin_lock_irq(&phba->hbalock);
756 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
757 spin_unlock_irq(&phba->hbalock);
758 lpfc_offline_prep(phba);
761 lpfc_reset_barrier(phba);
762 lpfc_sli_brdreset(phba);
763 lpfc_hba_down_post(phba);
764 lpfc_sli_brdready(phba, HS_MBRDY);
765 lpfc_unblock_mgmt_io(phba);
766 phba->link_state = LPFC_HBA_ERROR;
771 * lpfc_handle_eratt: The HBA hardware error handler.
772 * @phba: pointer to lpfc hba data structure.
774 * This routine is invoked to handle the following HBA hardware error
776 * 1 - HBA error attention interrupt
777 * 2 - DMA ring index out of range
778 * 3 - Mailbox command came back as unknown
781 lpfc_handle_eratt(struct lpfc_hba *phba)
783 struct lpfc_vport *vport = phba->pport;
784 struct lpfc_sli *psli = &phba->sli;
785 struct lpfc_sli_ring *pring;
787 unsigned long temperature;
788 struct temp_event temp_event_data;
789 struct Scsi_Host *shost;
791 /* If the pci channel is offline, ignore possible errors,
792 * since we cannot communicate with the pci card anyway. */
793 if (pci_channel_offline(phba->pcidev))
795 /* If resets are disabled then leave the HBA alone and return */
796 if (!phba->cfg_enable_hba_reset)
799 if (phba->work_hs & HS_FFER6) {
800 /* Re-establishing Link */
801 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
802 "1301 Re-establishing Link "
803 "Data: x%x x%x x%x\n",
805 phba->work_status[0], phba->work_status[1]);
807 spin_lock_irq(&phba->hbalock);
808 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
809 spin_unlock_irq(&phba->hbalock);
812 * Firmware stops when it triggled erratt with HS_FFER6.
813 * That could cause the I/Os dropped by the firmware.
814 * Error iocb (I/O) on txcmplq and let the SCSI layer
815 * retry it after re-establishing link.
817 pring = &psli->ring[psli->fcp_ring];
818 lpfc_sli_abort_iocb_ring(phba, pring);
821 * There was a firmware error. Take the hba offline and then
822 * attempt to restart it.
824 lpfc_offline_prep(phba);
826 lpfc_sli_brdrestart(phba);
827 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
828 lpfc_unblock_mgmt_io(phba);
831 lpfc_unblock_mgmt_io(phba);
832 } else if (phba->work_hs & HS_CRIT_TEMP) {
833 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
834 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
835 temp_event_data.event_code = LPFC_CRIT_TEMP;
836 temp_event_data.data = (uint32_t)temperature;
838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
839 "0406 Adapter maximum temperature exceeded "
840 "(%ld), taking this port offline "
841 "Data: x%x x%x x%x\n",
842 temperature, phba->work_hs,
843 phba->work_status[0], phba->work_status[1]);
845 shost = lpfc_shost_from_vport(phba->pport);
846 fc_host_post_vendor_event(shost, fc_get_event_number(),
847 sizeof(temp_event_data),
848 (char *) &temp_event_data,
850 | PCI_VENDOR_ID_EMULEX);
852 spin_lock_irq(&phba->hbalock);
853 phba->over_temp_state = HBA_OVER_TEMP;
854 spin_unlock_irq(&phba->hbalock);
855 lpfc_offline_eratt(phba);
858 /* The if clause above forces this code path when the status
859 * failure is a value other than FFER6. Do not call the offline
860 * twice. This is the adapter hardware error path.
862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
863 "0457 Adapter Hardware Error "
864 "Data: x%x x%x x%x\n",
866 phba->work_status[0], phba->work_status[1]);
868 event_data = FC_REG_DUMP_EVENT;
869 shost = lpfc_shost_from_vport(vport);
870 fc_host_post_vendor_event(shost, fc_get_event_number(),
871 sizeof(event_data), (char *) &event_data,
872 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
874 lpfc_offline_eratt(phba);
879 * lpfc_handle_latt: The HBA link event handler.
880 * @phba: pointer to lpfc hba data structure.
882 * This routine is invoked from the worker thread to handle a HBA host
883 * attention link event.
886 lpfc_handle_latt(struct lpfc_hba *phba)
888 struct lpfc_vport *vport = phba->pport;
889 struct lpfc_sli *psli = &phba->sli;
891 volatile uint32_t control;
892 struct lpfc_dmabuf *mp;
895 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
898 goto lpfc_handle_latt_err_exit;
901 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
904 goto lpfc_handle_latt_free_pmb;
907 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
910 goto lpfc_handle_latt_free_mp;
913 /* Cleanup any outstanding ELS commands */
914 lpfc_els_flush_all_cmd(phba);
916 psli->slistat.link_event++;
917 lpfc_read_la(phba, pmb, mp);
918 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
920 /* Block ELS IOCBs until we have processed this mbox command */
921 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
922 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
923 if (rc == MBX_NOT_FINISHED) {
925 goto lpfc_handle_latt_free_mbuf;
928 /* Clear Link Attention in HA REG */
929 spin_lock_irq(&phba->hbalock);
930 writel(HA_LATT, phba->HAregaddr);
931 readl(phba->HAregaddr); /* flush */
932 spin_unlock_irq(&phba->hbalock);
936 lpfc_handle_latt_free_mbuf:
937 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
938 lpfc_mbuf_free(phba, mp->virt, mp->phys);
939 lpfc_handle_latt_free_mp:
941 lpfc_handle_latt_free_pmb:
942 mempool_free(pmb, phba->mbox_mem_pool);
943 lpfc_handle_latt_err_exit:
944 /* Enable Link attention interrupts */
945 spin_lock_irq(&phba->hbalock);
946 psli->sli_flag |= LPFC_PROCESS_LA;
947 control = readl(phba->HCregaddr);
948 control |= HC_LAINT_ENA;
949 writel(control, phba->HCregaddr);
950 readl(phba->HCregaddr); /* flush */
952 /* Clear Link Attention in HA REG */
953 writel(HA_LATT, phba->HAregaddr);
954 readl(phba->HAregaddr); /* flush */
955 spin_unlock_irq(&phba->hbalock);
957 phba->link_state = LPFC_HBA_ERROR;
959 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
960 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
966 * lpfc_parse_vpd: Parse VPD (Vital Product Data).
967 * @phba: pointer to lpfc hba data structure.
968 * @vpd: pointer to the vital product data.
969 * @len: length of the vital product data in bytes.
971 * This routine parses the Vital Product Data (VPD). The VPD is treated as
972 * an array of characters. In this routine, the ModelName, ProgramType, and
973 * ModelDesc, etc. fields of the phba data structure will be populated.
976 * 0 - pointer to the VPD passed in is NULL
980 lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
982 uint8_t lenlo, lenhi;
992 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
993 "0455 Vital Product Data: x%x x%x x%x x%x\n",
994 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
996 while (!finished && (index < (len - 4))) {
997 switch (vpd[index]) {
1005 i = ((((unsigned short)lenhi) << 8) + lenlo);
1014 Length = ((((unsigned short)lenhi) << 8) + lenlo);
1015 if (Length > len - index)
1016 Length = len - index;
1017 while (Length > 0) {
1018 /* Look for Serial Number */
1019 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1026 phba->SerialNumber[j++] = vpd[index++];
1030 phba->SerialNumber[j] = 0;
1033 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
1034 phba->vpd_flag |= VPD_MODEL_DESC;
1041 phba->ModelDesc[j++] = vpd[index++];
1045 phba->ModelDesc[j] = 0;
1048 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
1049 phba->vpd_flag |= VPD_MODEL_NAME;
1056 phba->ModelName[j++] = vpd[index++];
1060 phba->ModelName[j] = 0;
1063 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
1064 phba->vpd_flag |= VPD_PROGRAM_TYPE;
1071 phba->ProgramType[j++] = vpd[index++];
1075 phba->ProgramType[j] = 0;
1078 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
1079 phba->vpd_flag |= VPD_PORT;
1086 phba->Port[j++] = vpd[index++];
1116 * lpfc_get_hba_model_desc: Retrieve HBA device model name and description.
1117 * @phba: pointer to lpfc hba data structure.
1118 * @mdp: pointer to the data structure to hold the derived model name.
1119 * @descp: pointer to the data structure to hold the derived description.
1121 * This routine retrieves HBA's description based on its registered PCI device
1122 * ID. The @descp passed into this function points to an array of 256 chars. It
1123 * shall be returned with the model name, maximum speed, and the host bus type.
1124 * The @mdp passed into this function points to an array of 80 chars. When the
1125 * function returns, the @mdp will be filled with the model name.
1128 lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1131 uint16_t dev_id = phba->pcidev->device;
1137 } m = {"<Unknown>", 0, ""};
1139 if (mdp && mdp[0] != '\0'
1140 && descp && descp[0] != '\0')
1143 if (phba->lmt & LMT_10Gb)
1145 else if (phba->lmt & LMT_8Gb)
1147 else if (phba->lmt & LMT_4Gb)
1149 else if (phba->lmt & LMT_2Gb)
1157 case PCI_DEVICE_ID_FIREFLY:
1158 m = (typeof(m)){"LP6000", max_speed, "PCI"};
1160 case PCI_DEVICE_ID_SUPERFLY:
1161 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1162 m = (typeof(m)){"LP7000", max_speed, "PCI"};
1164 m = (typeof(m)){"LP7000E", max_speed, "PCI"};
1166 case PCI_DEVICE_ID_DRAGONFLY:
1167 m = (typeof(m)){"LP8000", max_speed, "PCI"};
1169 case PCI_DEVICE_ID_CENTAUR:
1170 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1171 m = (typeof(m)){"LP9002", max_speed, "PCI"};
1173 m = (typeof(m)){"LP9000", max_speed, "PCI"};
1175 case PCI_DEVICE_ID_RFLY:
1176 m = (typeof(m)){"LP952", max_speed, "PCI"};
1178 case PCI_DEVICE_ID_PEGASUS:
1179 m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
1181 case PCI_DEVICE_ID_THOR:
1182 m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
1184 case PCI_DEVICE_ID_VIPER:
1185 m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
1187 case PCI_DEVICE_ID_PFLY:
1188 m = (typeof(m)){"LP982", max_speed, "PCI-X"};
1190 case PCI_DEVICE_ID_TFLY:
1191 m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
1193 case PCI_DEVICE_ID_HELIOS:
1194 m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
1196 case PCI_DEVICE_ID_HELIOS_SCSP:
1197 m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
1199 case PCI_DEVICE_ID_HELIOS_DCSP:
1200 m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
1202 case PCI_DEVICE_ID_NEPTUNE:
1203 m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
1205 case PCI_DEVICE_ID_NEPTUNE_SCSP:
1206 m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
1208 case PCI_DEVICE_ID_NEPTUNE_DCSP:
1209 m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
1211 case PCI_DEVICE_ID_BMID:
1212 m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
1214 case PCI_DEVICE_ID_BSMB:
1215 m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
1217 case PCI_DEVICE_ID_ZEPHYR:
1218 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1220 case PCI_DEVICE_ID_ZEPHYR_SCSP:
1221 m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
1223 case PCI_DEVICE_ID_ZEPHYR_DCSP:
1224 m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
1226 case PCI_DEVICE_ID_ZMID:
1227 m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
1229 case PCI_DEVICE_ID_ZSMB:
1230 m = (typeof(m)){"LPe111", max_speed, "PCIe"};
1232 case PCI_DEVICE_ID_LP101:
1233 m = (typeof(m)){"LP101", max_speed, "PCI-X"};
1235 case PCI_DEVICE_ID_LP10000S:
1236 m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
1238 case PCI_DEVICE_ID_LP11000S:
1239 m = (typeof(m)){"LP11000-S", max_speed,
1242 case PCI_DEVICE_ID_LPE11000S:
1243 m = (typeof(m)){"LPe11000-S", max_speed,
1246 case PCI_DEVICE_ID_SAT:
1247 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
1249 case PCI_DEVICE_ID_SAT_MID:
1250 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
1252 case PCI_DEVICE_ID_SAT_SMB:
1253 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
1255 case PCI_DEVICE_ID_SAT_DCSP:
1256 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
1258 case PCI_DEVICE_ID_SAT_SCSP:
1259 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
1261 case PCI_DEVICE_ID_SAT_S:
1262 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
1265 m = (typeof(m)){ NULL };
1269 if (mdp && mdp[0] == '\0')
1270 snprintf(mdp, 79,"%s", m.name);
1271 if (descp && descp[0] == '\0')
1272 snprintf(descp, 255,
1273 "Emulex %s %dGb %s Fibre Channel Adapter",
1274 m.name, m.max_speed, m.bus);
1278 * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring.
1279 * @phba: pointer to lpfc hba data structure.
1280 * @pring: pointer to a IOCB ring.
1281 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1283 * This routine posts a given number of IOCBs with the associated DMA buffer
1284 * descriptors specified by the cnt argument to the given IOCB ring.
1287 * The number of IOCBs NOT able to be posted to the IOCB ring.
1290 lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
1293 struct lpfc_iocbq *iocb;
1294 struct lpfc_dmabuf *mp1, *mp2;
1296 cnt += pring->missbufcnt;
1298 /* While there are buffers to post */
1300 /* Allocate buffer for command iocb */
1301 iocb = lpfc_sli_get_iocbq(phba);
1303 pring->missbufcnt = cnt;
1308 /* 2 buffers can be posted per command */
1309 /* Allocate buffer to post */
1310 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1312 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
1313 if (!mp1 || !mp1->virt) {
1315 lpfc_sli_release_iocbq(phba, iocb);
1316 pring->missbufcnt = cnt;
1320 INIT_LIST_HEAD(&mp1->list);
1321 /* Allocate buffer to post */
1323 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1325 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
1327 if (!mp2 || !mp2->virt) {
1329 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1331 lpfc_sli_release_iocbq(phba, iocb);
1332 pring->missbufcnt = cnt;
1336 INIT_LIST_HEAD(&mp2->list);
1341 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
1342 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
1343 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
1344 icmd->ulpBdeCount = 1;
1347 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
1348 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
1349 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
1351 icmd->ulpBdeCount = 2;
1354 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1357 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1358 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1362 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
1366 lpfc_sli_release_iocbq(phba, iocb);
1367 pring->missbufcnt = cnt;
1370 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1372 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1374 pring->missbufcnt = 0;
1379 * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring.
1380 * @phba: pointer to lpfc hba data structure.
1382 * This routine posts initial receive IOCB buffers to the ELS ring. The
1383 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1387 * 0 - success (currently always success)
1390 lpfc_post_rcv_buf(struct lpfc_hba *phba)
1392 struct lpfc_sli *psli = &phba->sli;
1394 /* Ring 0, ELS / CT buffers */
1395 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
1396 /* Ring 2 - FCP no buffers needed */
1401 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1404 * lpfc_sha_init: Set up initial array of hash table entries.
1405 * @HashResultPointer: pointer to an array as hash table.
1407 * This routine sets up the initial values to the array of hash table entries
1411 lpfc_sha_init(uint32_t * HashResultPointer)
1413 HashResultPointer[0] = 0x67452301;
1414 HashResultPointer[1] = 0xEFCDAB89;
1415 HashResultPointer[2] = 0x98BADCFE;
1416 HashResultPointer[3] = 0x10325476;
1417 HashResultPointer[4] = 0xC3D2E1F0;
1421 * lpfc_sha_iterate: Iterate initial hash table with the working hash table.
1422 * @HashResultPointer: pointer to an initial/result hash table.
1423 * @HashWorkingPointer: pointer to an working hash table.
1425 * This routine iterates an initial hash table pointed by @HashResultPointer
1426 * with the values from the working hash table pointeed by @HashWorkingPointer.
1427 * The results are putting back to the initial hash table, returned through
1428 * the @HashResultPointer as the result hash table.
1431 lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
1435 uint32_t A, B, C, D, E;
1438 HashWorkingPointer[t] =
1440 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
1442 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
1443 } while (++t <= 79);
1445 A = HashResultPointer[0];
1446 B = HashResultPointer[1];
1447 C = HashResultPointer[2];
1448 D = HashResultPointer[3];
1449 E = HashResultPointer[4];
1453 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
1454 } else if (t < 40) {
1455 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
1456 } else if (t < 60) {
1457 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
1459 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
1461 TEMP += S(5, A) + E + HashWorkingPointer[t];
1467 } while (++t <= 79);
1469 HashResultPointer[0] += A;
1470 HashResultPointer[1] += B;
1471 HashResultPointer[2] += C;
1472 HashResultPointer[3] += D;
1473 HashResultPointer[4] += E;
1478 * lpfc_challenge_key: Create challenge key based on WWPN of the HBA.
1479 * @RandomChallenge: pointer to the entry of host challenge random number array.
1480 * @HashWorking: pointer to the entry of the working hash array.
1482 * This routine calculates the working hash array referred by @HashWorking
1483 * from the challenge random numbers associated with the host, referred by
1484 * @RandomChallenge. The result is put into the entry of the working hash
1485 * array and returned by reference through @HashWorking.
1488 lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
1490 *HashWorking = (*RandomChallenge ^ *HashWorking);
1494 * lpfc_hba_init: Perform special handling for LC HBA initialization.
1495 * @phba: pointer to lpfc hba data structure.
1496 * @hbainit: pointer to an array of unsigned 32-bit integers.
1498 * This routine performs the special handling for LC HBA initialization.
1501 lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1504 uint32_t *HashWorking;
1505 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1507 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
1511 HashWorking[0] = HashWorking[78] = *pwwnn++;
1512 HashWorking[1] = HashWorking[79] = *pwwnn;
1514 for (t = 0; t < 7; t++)
1515 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
1517 lpfc_sha_init(hbainit);
1518 lpfc_sha_iterate(hbainit, HashWorking);
1523 * lpfc_cleanup: Performs vport cleanups before deleting a vport.
1524 * @vport: pointer to a virtual N_Port data structure.
1526 * This routine performs the necessary cleanups before deleting the @vport.
1527 * It invokes the discovery state machine to perform necessary state
1528 * transitions and to release the ndlps associated with the @vport. Note,
1529 * the physical port is treated as @vport 0.
1532 lpfc_cleanup(struct lpfc_vport *vport)
1534 struct lpfc_hba *phba = vport->phba;
1535 struct lpfc_nodelist *ndlp, *next_ndlp;
1538 if (phba->link_state > LPFC_LINK_DOWN)
1539 lpfc_port_link_failure(vport);
1541 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1542 if (!NLP_CHK_NODE_ACT(ndlp)) {
1543 ndlp = lpfc_enable_node(vport, ndlp,
1544 NLP_STE_UNUSED_NODE);
1547 spin_lock_irq(&phba->ndlp_lock);
1548 NLP_SET_FREE_REQ(ndlp);
1549 spin_unlock_irq(&phba->ndlp_lock);
1550 /* Trigger the release of the ndlp memory */
1554 spin_lock_irq(&phba->ndlp_lock);
1555 if (NLP_CHK_FREE_REQ(ndlp)) {
1556 /* The ndlp should not be in memory free mode already */
1557 spin_unlock_irq(&phba->ndlp_lock);
1560 /* Indicate request for freeing ndlp memory */
1561 NLP_SET_FREE_REQ(ndlp);
1562 spin_unlock_irq(&phba->ndlp_lock);
1564 if (vport->port_type != LPFC_PHYSICAL_PORT &&
1565 ndlp->nlp_DID == Fabric_DID) {
1566 /* Just free up ndlp with Fabric_DID for vports */
1571 if (ndlp->nlp_type & NLP_FABRIC)
1572 lpfc_disc_state_machine(vport, ndlp, NULL,
1573 NLP_EVT_DEVICE_RECOVERY);
1575 lpfc_disc_state_machine(vport, ndlp, NULL,
1580 /* At this point, ALL ndlp's should be gone
1581 * because of the previous NLP_EVT_DEVICE_RM.
1582 * Lets wait for this to happen, if needed.
1584 while (!list_empty(&vport->fc_nodes)) {
1587 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1588 "0233 Nodelist not empty\n");
1589 list_for_each_entry_safe(ndlp, next_ndlp,
1590 &vport->fc_nodes, nlp_listp) {
1591 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
1593 "0282 did:x%x ndlp:x%p "
1594 "usgmap:x%x refcnt:%d\n",
1595 ndlp->nlp_DID, (void *)ndlp,
1598 &ndlp->kref.refcount));
1603 /* Wait for any activity on ndlps to settle */
1610 * lpfc_stop_vport_timers: Stop all the timers associated with a vport.
1611 * @vport: pointer to a virtual N_Port data structure.
1613 * This routine stops all the timers associated with a @vport. This function
1614 * is invoked before disabling or deleting a @vport. Note that the physical
1615 * port is treated as @vport 0.
1618 lpfc_stop_vport_timers(struct lpfc_vport *vport)
1620 del_timer_sync(&vport->els_tmofunc);
1621 del_timer_sync(&vport->fc_fdmitmo);
1622 lpfc_can_disctmo(vport);
1627 * lpfc_stop_phba_timers: Stop all the timers associated with an HBA.
1628 * @phba: pointer to lpfc hba data structure.
1630 * This routine stops all the timers associated with a HBA. This function is
1631 * invoked before either putting a HBA offline or unloading the driver.
1634 lpfc_stop_phba_timers(struct lpfc_hba *phba)
1636 del_timer_sync(&phba->fcp_poll_timer);
1637 lpfc_stop_vport_timers(phba->pport);
1638 del_timer_sync(&phba->sli.mbox_tmo);
1639 del_timer_sync(&phba->fabric_block_timer);
1640 phba->hb_outstanding = 0;
1641 del_timer_sync(&phba->hb_tmofunc);
1646 * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked.
1647 * @phba: pointer to lpfc hba data structure.
1649 * This routine marks a HBA's management interface as blocked. Once the HBA's
1650 * management interface is marked as blocked, all the user space access to
1651 * the HBA, whether they are from sysfs interface or libdfc interface will
1652 * all be blocked. The HBA is set to block the management interface when the
1653 * driver prepares the HBA interface for online or offline.
1656 lpfc_block_mgmt_io(struct lpfc_hba * phba)
1658 unsigned long iflag;
1660 spin_lock_irqsave(&phba->hbalock, iflag);
1661 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1662 spin_unlock_irqrestore(&phba->hbalock, iflag);
1666 * lpfc_online: Initialize and bring a HBA online.
1667 * @phba: pointer to lpfc hba data structure.
1669 * This routine initializes the HBA and brings a HBA online. During this
1670 * process, the management interface is blocked to prevent user space access
1671 * to the HBA interfering with the driver initialization.
1678 lpfc_online(struct lpfc_hba *phba)
1680 struct lpfc_vport *vport = phba->pport;
1681 struct lpfc_vport **vports;
1687 if (!(vport->fc_flag & FC_OFFLINE_MODE))
1690 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1691 "0458 Bring Adapter online\n");
1693 lpfc_block_mgmt_io(phba);
1695 if (!lpfc_sli_queue_setup(phba)) {
1696 lpfc_unblock_mgmt_io(phba);
1700 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1701 lpfc_unblock_mgmt_io(phba);
1705 vports = lpfc_create_vport_work_array(phba);
1707 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1708 struct Scsi_Host *shost;
1709 shost = lpfc_shost_from_vport(vports[i]);
1710 spin_lock_irq(shost->host_lock);
1711 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
1712 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1713 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1714 spin_unlock_irq(shost->host_lock);
1716 lpfc_destroy_vport_work_array(phba, vports);
1718 lpfc_unblock_mgmt_io(phba);
1723 * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked.
1724 * @phba: pointer to lpfc hba data structure.
1726 * This routine marks a HBA's management interface as not blocked. Once the
1727 * HBA's management interface is marked as not blocked, all the user space
1728 * access to the HBA, whether they are from sysfs interface or libdfc
1729 * interface will be allowed. The HBA is set to block the management interface
1730 * when the driver prepares the HBA interface for online or offline and then
1731 * set to unblock the management interface afterwards.
1734 lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1736 unsigned long iflag;
1738 spin_lock_irqsave(&phba->hbalock, iflag);
1739 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1740 spin_unlock_irqrestore(&phba->hbalock, iflag);
1744 * lpfc_offline_prep: Prepare a HBA to be brought offline.
1745 * @phba: pointer to lpfc hba data structure.
1747 * This routine is invoked to prepare a HBA to be brought offline. It performs
1748 * unregistration login to all the nodes on all vports and flushes the mailbox
1749 * queue to make it ready to be brought offline.
1752 lpfc_offline_prep(struct lpfc_hba * phba)
1754 struct lpfc_vport *vport = phba->pport;
1755 struct lpfc_nodelist *ndlp, *next_ndlp;
1756 struct lpfc_vport **vports;
1759 if (vport->fc_flag & FC_OFFLINE_MODE)
1762 lpfc_block_mgmt_io(phba);
1764 lpfc_linkdown(phba);
1766 /* Issue an unreg_login to all nodes on all vports */
1767 vports = lpfc_create_vport_work_array(phba);
1768 if (vports != NULL) {
1769 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1770 struct Scsi_Host *shost;
1772 if (vports[i]->load_flag & FC_UNLOADING)
1774 shost = lpfc_shost_from_vport(vports[i]);
1775 list_for_each_entry_safe(ndlp, next_ndlp,
1776 &vports[i]->fc_nodes,
1778 if (!NLP_CHK_NODE_ACT(ndlp))
1780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1782 if (ndlp->nlp_type & NLP_FABRIC) {
1783 lpfc_disc_state_machine(vports[i], ndlp,
1784 NULL, NLP_EVT_DEVICE_RECOVERY);
1785 lpfc_disc_state_machine(vports[i], ndlp,
1786 NULL, NLP_EVT_DEVICE_RM);
1788 spin_lock_irq(shost->host_lock);
1789 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1790 spin_unlock_irq(shost->host_lock);
1791 lpfc_unreg_rpi(vports[i], ndlp);
1795 lpfc_destroy_vport_work_array(phba, vports);
1797 lpfc_sli_flush_mbox_queue(phba);
1801 * lpfc_offline: Bring a HBA offline.
1802 * @phba: pointer to lpfc hba data structure.
1804 * This routine actually brings a HBA offline. It stops all the timers
1805 * associated with the HBA, brings down the SLI layer, and eventually
1806 * marks the HBA as in offline state for the upper layer protocol.
1809 lpfc_offline(struct lpfc_hba *phba)
1811 struct Scsi_Host *shost;
1812 struct lpfc_vport **vports;
1815 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1818 /* stop all timers associated with this hba */
1819 lpfc_stop_phba_timers(phba);
1820 vports = lpfc_create_vport_work_array(phba);
1822 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
1823 lpfc_stop_vport_timers(vports[i]);
1824 lpfc_destroy_vport_work_array(phba, vports);
1825 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1826 "0460 Bring Adapter offline\n");
1827 /* Bring down the SLI Layer and cleanup. The HBA is offline
1829 lpfc_sli_hba_down(phba);
1830 spin_lock_irq(&phba->hbalock);
1832 spin_unlock_irq(&phba->hbalock);
1833 vports = lpfc_create_vport_work_array(phba);
1835 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1836 shost = lpfc_shost_from_vport(vports[i]);
1837 spin_lock_irq(shost->host_lock);
1838 vports[i]->work_port_events = 0;
1839 vports[i]->fc_flag |= FC_OFFLINE_MODE;
1840 spin_unlock_irq(shost->host_lock);
1842 lpfc_destroy_vport_work_array(phba, vports);
1846 * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists.
1847 * @phba: pointer to lpfc hba data structure.
1849 * This routine is to free all the SCSI buffers and IOCBs from the driver
1850 * list back to kernel. It is called from lpfc_pci_remove_one to free
1851 * the internal resources before the device is removed from the system.
1854 * 0 - successful (for now, it always returns 0)
1857 lpfc_scsi_free(struct lpfc_hba *phba)
1859 struct lpfc_scsi_buf *sb, *sb_next;
1860 struct lpfc_iocbq *io, *io_next;
1862 spin_lock_irq(&phba->hbalock);
1863 /* Release all the lpfc_scsi_bufs maintained by this host. */
1864 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1865 list_del(&sb->list);
1866 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1869 phba->total_scsi_bufs--;
1872 /* Release all the lpfc_iocbq entries maintained by this host. */
1873 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
1874 list_del(&io->list);
1876 phba->total_iocbq_bufs--;
1879 spin_unlock_irq(&phba->hbalock);
1885 * lpfc_create_port: Create an FC port.
1886 * @phba: pointer to lpfc hba data structure.
1887 * @instance: a unique integer ID to this FC port.
1888 * @dev: pointer to the device data structure.
1890 * This routine creates a FC port for the upper layer protocol. The FC port
1891 * can be created on top of either a physical port or a virtual port provided
1892 * by the HBA. This routine also allocates a SCSI host data structure (shost)
1893 * and associates the FC port created before adding the shost into the SCSI
1897 * @vport - pointer to the virtual N_Port data structure.
1898 * NULL - port create failed.
1901 lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
1903 struct lpfc_vport *vport;
1904 struct Scsi_Host *shost;
1907 if (dev != &phba->pcidev->dev)
1908 shost = scsi_host_alloc(&lpfc_vport_template,
1909 sizeof(struct lpfc_vport));
1911 shost = scsi_host_alloc(&lpfc_template,
1912 sizeof(struct lpfc_vport));
1916 vport = (struct lpfc_vport *) shost->hostdata;
1918 vport->load_flag |= FC_LOADING;
1919 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1920 vport->fc_rscn_flush = 0;
1922 lpfc_get_vport_cfgparam(vport);
1923 shost->unique_id = instance;
1924 shost->max_id = LPFC_MAX_TARGET;
1925 shost->max_lun = vport->cfg_max_luns;
1926 shost->this_id = -1;
1927 shost->max_cmd_len = 16;
1929 * Set initial can_queue value since 0 is no longer supported and
1930 * scsi_add_host will fail. This will be adjusted later based on the
1931 * max xri value determined in hba setup.
1933 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1934 if (dev != &phba->pcidev->dev) {
1935 shost->transportt = lpfc_vport_transport_template;
1936 vport->port_type = LPFC_NPIV_PORT;
1938 shost->transportt = lpfc_transport_template;
1939 vport->port_type = LPFC_PHYSICAL_PORT;
1942 /* Initialize all internally managed lists. */
1943 INIT_LIST_HEAD(&vport->fc_nodes);
1944 spin_lock_init(&vport->work_port_lock);
1946 init_timer(&vport->fc_disctmo);
1947 vport->fc_disctmo.function = lpfc_disc_timeout;
1948 vport->fc_disctmo.data = (unsigned long)vport;
1950 init_timer(&vport->fc_fdmitmo);
1951 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1952 vport->fc_fdmitmo.data = (unsigned long)vport;
1954 init_timer(&vport->els_tmofunc);
1955 vport->els_tmofunc.function = lpfc_els_timeout;
1956 vport->els_tmofunc.data = (unsigned long)vport;
1958 error = scsi_add_host(shost, dev);
1962 spin_lock_irq(&phba->hbalock);
1963 list_add_tail(&vport->listentry, &phba->port_list);
1964 spin_unlock_irq(&phba->hbalock);
1968 scsi_host_put(shost);
1974 * destroy_port: Destroy an FC port.
1975 * @vport: pointer to an lpfc virtual N_Port data structure.
1977 * This routine destroys a FC port from the upper layer protocol. All the
1978 * resources associated with the port are released.
1981 destroy_port(struct lpfc_vport *vport)
1983 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1984 struct lpfc_hba *phba = vport->phba;
1986 kfree(vport->vname);
1988 lpfc_debugfs_terminate(vport);
1989 fc_remove_host(shost);
1990 scsi_remove_host(shost);
1992 spin_lock_irq(&phba->hbalock);
1993 list_del_init(&vport->listentry);
1994 spin_unlock_irq(&phba->hbalock);
1996 lpfc_cleanup(vport);
2001 * lpfc_get_instance: Get a unique integer ID.
2003 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2004 * uses the kernel idr facility to perform the task.
2007 * instance - a unique integer ID allocated as the new instance.
2008 * -1 - lpfc get instance failed.
2011 lpfc_get_instance(void)
2015 /* Assign an unused number */
2016 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
2018 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
2024 * lpfc_scan_finished: method for SCSI layer to detect whether scan is done.
2025 * @shost: pointer to SCSI host data structure.
2026 * @time: elapsed time of the scan in jiffies.
2028 * This routine is called by the SCSI layer with a SCSI host to determine
2029 * whether the scan host is finished.
2031 * Note: there is no scan_start function as adapter initialization will have
2032 * asynchronously kicked off the link initialization.
2035 * 0 - SCSI host scan is not over yet.
2036 * 1 - SCSI host scan is over.
2038 int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
2040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2041 struct lpfc_hba *phba = vport->phba;
2044 spin_lock_irq(shost->host_lock);
2046 if (vport->load_flag & FC_UNLOADING) {
2050 if (time >= 30 * HZ) {
2051 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2052 "0461 Scanning longer than 30 "
2053 "seconds. Continuing initialization\n");
2057 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
2058 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2059 "0465 Link down longer than 15 "
2060 "seconds. Continuing initialization\n");
2065 if (vport->port_state != LPFC_VPORT_READY)
2067 if (vport->num_disc_nodes || vport->fc_prli_sent)
2069 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
2071 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
2077 spin_unlock_irq(shost->host_lock);
2082 * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port.
2083 * @shost: pointer to SCSI host data structure.
2085 * This routine initializes a given SCSI host attributes on a FC port. The
2086 * SCSI host can be either on top of a physical port or a virtual port.
2088 void lpfc_host_attrib_init(struct Scsi_Host *shost)
2090 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2091 struct lpfc_hba *phba = vport->phba;
2093 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
2096 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
2097 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
2098 fc_host_supported_classes(shost) = FC_COS_CLASS3;
2100 memset(fc_host_supported_fc4s(shost), 0,
2101 sizeof(fc_host_supported_fc4s(shost)));
2102 fc_host_supported_fc4s(shost)[2] = 1;
2103 fc_host_supported_fc4s(shost)[7] = 1;
2105 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
2106 sizeof fc_host_symbolic_name(shost));
2108 fc_host_supported_speeds(shost) = 0;
2109 if (phba->lmt & LMT_10Gb)
2110 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
2111 if (phba->lmt & LMT_8Gb)
2112 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
2113 if (phba->lmt & LMT_4Gb)
2114 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
2115 if (phba->lmt & LMT_2Gb)
2116 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
2117 if (phba->lmt & LMT_1Gb)
2118 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
2120 fc_host_maxframe_size(shost) =
2121 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
2122 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
2124 /* This value is also unchanging */
2125 memset(fc_host_active_fc4s(shost), 0,
2126 sizeof(fc_host_active_fc4s(shost)));
2127 fc_host_active_fc4s(shost)[2] = 1;
2128 fc_host_active_fc4s(shost)[7] = 1;
2130 fc_host_max_npiv_vports(shost) = phba->max_vpi;
2131 spin_lock_irq(shost->host_lock);
2132 vport->load_flag &= ~FC_LOADING;
2133 spin_unlock_irq(shost->host_lock);
2137 * lpfc_enable_msix: Enable MSI-X interrupt mode.
2138 * @phba: pointer to lpfc hba data structure.
2140 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel
2141 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that
2142 * pci_enable_msix(), once invoked, enables either all or nothing, depending
2143 * on the current availability of PCI vector resources. The device driver is
2144 * responsible for calling the individual request_irq() to register each MSI-X
2145 * vector with a interrupt handler, which is done in this function. Note that
2146 * later when device is unloading, the driver should always call free_irq()
2147 * on all MSI-X vectors it has done request_irq() on before calling
2148 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
2149 * will be left with MSI-X enabled and leaks its vectors.
2153 * other values - error
2156 lpfc_enable_msix(struct lpfc_hba *phba)
2160 phba->msix_entries[0].entry = 0;
2161 phba->msix_entries[0].vector = 0;
2163 error = pci_enable_msix(phba->pcidev, phba->msix_entries,
2164 ARRAY_SIZE(phba->msix_entries));
2166 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2167 "0420 Enable MSI-X failed (%d), continuing "
2168 "with MSI\n", error);
2169 pci_disable_msix(phba->pcidev);
2173 error = request_irq(phba->msix_entries[0].vector, lpfc_intr_handler, 0,
2174 LPFC_DRIVER_NAME, phba);
2176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2177 "0421 MSI-X request_irq failed (%d), "
2178 "continuing with MSI\n", error);
2179 pci_disable_msix(phba->pcidev);
2185 * lpfc_disable_msix: Disable MSI-X interrupt mode.
2186 * @phba: pointer to lpfc hba data structure.
2188 * This routine is invoked to release the MSI-X vectors and then disable the
2189 * MSI-X interrupt mode.
2192 lpfc_disable_msix(struct lpfc_hba *phba)
2194 free_irq(phba->msix_entries[0].vector, phba);
2195 pci_disable_msix(phba->pcidev);
2199 * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem.
2200 * @pdev: pointer to PCI device
2201 * @pid: pointer to PCI device identifier
2203 * This routine is to be registered to the kernel's PCI subsystem. When an
2204 * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at
2205 * PCI device-specific information of the device and driver to see if the
2206 * driver state that it can support this kind of device. If the match is
2207 * successful, the driver core invokes this routine. If this routine
2208 * determines it can claim the HBA, it does all the initialization that it
2209 * needs to do to handle the HBA properly.
2212 * 0 - driver can claim the device
2213 * negative value - driver can not claim the device
2215 static int __devinit
2216 lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
2218 struct lpfc_vport *vport = NULL;
2219 struct lpfc_hba *phba;
2220 struct lpfc_sli *psli;
2221 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
2222 struct Scsi_Host *shost = NULL;
2224 unsigned long bar0map_len, bar2map_len;
2225 int error = -ENODEV, retval;
2228 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2230 if (pci_enable_device_mem(pdev))
2232 if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
2233 goto out_disable_device;
2235 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
2237 goto out_release_regions;
2239 spin_lock_init(&phba->hbalock);
2241 /* Initialize ndlp management spinlock */
2242 spin_lock_init(&phba->ndlp_lock);
2244 phba->pcidev = pdev;
2246 /* Assign an unused board number */
2247 if ((phba->brd_no = lpfc_get_instance()) < 0)
2250 INIT_LIST_HEAD(&phba->port_list);
2252 * Get all the module params for configuring this host and then
2253 * establish the host.
2255 lpfc_get_cfgparam(phba);
2256 phba->max_vpi = LPFC_MAX_VPI;
2258 /* Initialize timers used by driver */
2259 init_timer(&phba->hb_tmofunc);
2260 phba->hb_tmofunc.function = lpfc_hb_timeout;
2261 phba->hb_tmofunc.data = (unsigned long)phba;
2264 init_timer(&psli->mbox_tmo);
2265 psli->mbox_tmo.function = lpfc_mbox_timeout;
2266 psli->mbox_tmo.data = (unsigned long) phba;
2267 init_timer(&phba->fcp_poll_timer);
2268 phba->fcp_poll_timer.function = lpfc_poll_timeout;
2269 phba->fcp_poll_timer.data = (unsigned long) phba;
2270 init_timer(&phba->fabric_block_timer);
2271 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
2272 phba->fabric_block_timer.data = (unsigned long) phba;
2274 pci_set_master(pdev);
2275 pci_try_set_mwi(pdev);
2277 if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
2278 if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
2279 goto out_idr_remove;
2282 * Get the bus address of Bar0 and Bar2 and the number of bytes
2283 * required by each mapping.
2285 phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
2286 bar0map_len = pci_resource_len(phba->pcidev, 0);
2288 phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
2289 bar2map_len = pci_resource_len(phba->pcidev, 2);
2291 /* Map HBA SLIM to a kernel virtual address. */
2292 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
2293 if (!phba->slim_memmap_p) {
2295 dev_printk(KERN_ERR, &pdev->dev,
2296 "ioremap failed for SLIM memory.\n");
2297 goto out_idr_remove;
2300 /* Map HBA Control Registers to a kernel virtual address. */
2301 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
2302 if (!phba->ctrl_regs_memmap_p) {
2304 dev_printk(KERN_ERR, &pdev->dev,
2305 "ioremap failed for HBA control registers.\n");
2306 goto out_iounmap_slim;
2309 /* Allocate memory for SLI-2 structures */
2310 phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev,
2314 if (!phba->slim2p.virt)
2317 memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
2318 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
2319 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
2320 phba->IOCBs = (phba->slim2p.virt +
2321 offsetof(struct lpfc_sli2_slim, IOCBs));
2323 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
2324 lpfc_sli_hbq_size(),
2325 &phba->hbqslimp.phys,
2327 if (!phba->hbqslimp.virt)
2330 hbq_count = lpfc_sli_hbq_count();
2331 ptr = phba->hbqslimp.virt;
2332 for (i = 0; i < hbq_count; ++i) {
2333 phba->hbqs[i].hbq_virt = ptr;
2334 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
2335 ptr += (lpfc_hbq_defs[i]->entry_count *
2336 sizeof(struct lpfc_hbq_entry));
2338 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
2339 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
2341 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
2343 INIT_LIST_HEAD(&phba->hbqbuf_in_list);
2345 /* Initialize the SLI Layer to run with lpfc HBAs. */
2346 lpfc_sli_setup(phba);
2347 lpfc_sli_queue_setup(phba);
2349 retval = lpfc_mem_alloc(phba);
2352 goto out_free_hbqslimp;
2355 /* Initialize and populate the iocb list per host. */
2356 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
2357 for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
2358 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
2359 if (iocbq_entry == NULL) {
2360 printk(KERN_ERR "%s: only allocated %d iocbs of "
2361 "expected %d count. Unloading driver.\n",
2362 __func__, i, LPFC_IOCB_LIST_CNT);
2364 goto out_free_iocbq;
2367 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
2369 kfree (iocbq_entry);
2370 printk(KERN_ERR "%s: failed to allocate IOTAG. "
2371 "Unloading driver.\n",
2374 goto out_free_iocbq;
2377 spin_lock_irq(&phba->hbalock);
2378 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
2379 phba->total_iocbq_bufs++;
2380 spin_unlock_irq(&phba->hbalock);
2383 /* Initialize HBA structure */
2384 phba->fc_edtov = FF_DEF_EDTOV;
2385 phba->fc_ratov = FF_DEF_RATOV;
2386 phba->fc_altov = FF_DEF_ALTOV;
2387 phba->fc_arbtov = FF_DEF_ARBTOV;
2389 INIT_LIST_HEAD(&phba->work_list);
2390 phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
2391 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
2393 /* Initialize the wait queue head for the kernel thread */
2394 init_waitqueue_head(&phba->work_waitq);
2396 /* Startup the kernel thread for this host adapter. */
2397 phba->worker_thread = kthread_run(lpfc_do_work, phba,
2398 "lpfc_worker_%d", phba->brd_no);
2399 if (IS_ERR(phba->worker_thread)) {
2400 error = PTR_ERR(phba->worker_thread);
2401 goto out_free_iocbq;
2404 /* Initialize the list of scsi buffers used by driver for scsi IO. */
2405 spin_lock_init(&phba->scsi_buf_list_lock);
2406 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
2408 /* Initialize list of fabric iocbs */
2409 INIT_LIST_HEAD(&phba->fabric_iocb_list);
2411 /* Initialize list to save ELS buffers */
2412 INIT_LIST_HEAD(&phba->elsbuf);
2414 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
2416 goto out_kthread_stop;
2418 shost = lpfc_shost_from_vport(vport);
2419 phba->pport = vport;
2420 lpfc_debugfs_initialize(vport);
2422 pci_set_drvdata(pdev, shost);
2423 phba->intr_type = NONE;
2425 if (phba->cfg_use_msi == 2) {
2426 error = lpfc_enable_msix(phba);
2428 phba->intr_type = MSIX;
2431 /* Fallback to MSI if MSI-X initialization failed */
2432 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2433 retval = pci_enable_msi(phba->pcidev);
2435 phba->intr_type = MSI;
2437 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2438 "0452 Enable MSI failed, continuing "
2442 /* MSI-X is the only case the doesn't need to call request_irq */
2443 if (phba->intr_type != MSIX) {
2444 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2445 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable "
2448 "interrupt handler failed\n");
2450 goto out_disable_msi;
2451 } else if (phba->intr_type != MSI)
2452 phba->intr_type = INTx;
2455 phba->MBslimaddr = phba->slim_memmap_p;
2456 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
2457 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
2458 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
2459 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
2461 if (lpfc_alloc_sysfs_attr(vport)) {
2466 if (lpfc_sli_hba_setup(phba)) {
2468 goto out_remove_device;
2472 * hba setup may have changed the hba_queue_depth so we need to adjust
2473 * the value of can_queue.
2475 shost->can_queue = phba->cfg_hba_queue_depth - 10;
2477 lpfc_host_attrib_init(shost);
2479 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
2480 spin_lock_irq(shost->host_lock);
2481 lpfc_poll_start_timer(phba);
2482 spin_unlock_irq(shost->host_lock);
2485 scsi_scan_host(shost);
2490 lpfc_free_sysfs_attr(vport);
2491 spin_lock_irq(shost->host_lock);
2492 vport->load_flag |= FC_UNLOADING;
2493 spin_unlock_irq(shost->host_lock);
2495 lpfc_stop_phba_timers(phba);
2496 phba->pport->work_port_events = 0;
2498 if (phba->intr_type == MSIX)
2499 lpfc_disable_msix(phba);
2501 free_irq(phba->pcidev->irq, phba);
2504 if (phba->intr_type == MSI)
2505 pci_disable_msi(phba->pcidev);
2506 destroy_port(vport);
2508 kthread_stop(phba->worker_thread);
2510 list_for_each_entry_safe(iocbq_entry, iocbq_next,
2511 &phba->lpfc_iocb_list, list) {
2513 phba->total_iocbq_bufs--;
2515 lpfc_mem_free(phba);
2517 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2518 phba->hbqslimp.virt, phba->hbqslimp.phys);
2520 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2521 phba->slim2p.virt, phba->slim2p.phys);
2523 iounmap(phba->ctrl_regs_memmap_p);
2525 iounmap(phba->slim_memmap_p);
2527 idr_remove(&lpfc_hba_index, phba->brd_no);
2530 out_release_regions:
2531 pci_release_selected_regions(pdev, bars);
2533 pci_disable_device(pdev);
2535 pci_set_drvdata(pdev, NULL);
2537 scsi_host_put(shost);
2542 * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem.
2543 * @pdev: pointer to PCI device
2545 * This routine is to be registered to the kernel's PCI subsystem. When an
2546 * Emulex HBA is removed from PCI bus. It perform all the necessary cleanup
2547 * for the HBA device to be removed from the PCI subsystem properly.
2549 static void __devexit
2550 lpfc_pci_remove_one(struct pci_dev *pdev)
2552 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2554 struct lpfc_hba *phba = vport->phba;
2555 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
2557 spin_lock_irq(&phba->hbalock);
2558 vport->load_flag |= FC_UNLOADING;
2559 spin_unlock_irq(&phba->hbalock);
2561 kfree(vport->vname);
2562 lpfc_free_sysfs_attr(vport);
2564 kthread_stop(phba->worker_thread);
2566 fc_remove_host(shost);
2567 scsi_remove_host(shost);
2568 lpfc_cleanup(vport);
2571 * Bring down the SLI Layer. This step disable all interrupts,
2572 * clears the rings, discards all mailbox commands, and resets
2575 lpfc_sli_hba_down(phba);
2576 lpfc_sli_brdrestart(phba);
2578 lpfc_stop_phba_timers(phba);
2579 spin_lock_irq(&phba->hbalock);
2580 list_del_init(&vport->listentry);
2581 spin_unlock_irq(&phba->hbalock);
2583 lpfc_debugfs_terminate(vport);
2585 if (phba->intr_type == MSIX)
2586 lpfc_disable_msix(phba);
2588 free_irq(phba->pcidev->irq, phba);
2589 if (phba->intr_type == MSI)
2590 pci_disable_msi(phba->pcidev);
2593 pci_set_drvdata(pdev, NULL);
2594 scsi_host_put(shost);
2597 * Call scsi_free before mem_free since scsi bufs are released to their
2598 * corresponding pools here.
2600 lpfc_scsi_free(phba);
2601 lpfc_mem_free(phba);
2603 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
2604 phba->hbqslimp.virt, phba->hbqslimp.phys);
2606 /* Free resources associated with SLI2 interface */
2607 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2608 phba->slim2p.virt, phba->slim2p.phys);
2610 /* unmap adapter SLIM and Control Registers */
2611 iounmap(phba->ctrl_regs_memmap_p);
2612 iounmap(phba->slim_memmap_p);
2614 idr_remove(&lpfc_hba_index, phba->brd_no);
2618 pci_release_selected_regions(pdev, bars);
2619 pci_disable_device(pdev);
2623 * lpfc_io_error_detected: Driver method for handling PCI I/O error detected.
2624 * @pdev: pointer to PCI device.
2625 * @state: the current PCI connection state.
2627 * This routine is registered to the PCI subsystem for error handling. This
2628 * function is called by the PCI subsystem after a PCI bus error affecting
2629 * this device has been detected. When this function is invoked, it will
2630 * need to stop all the I/Os and interrupt(s) to the device. Once that is
2631 * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to
2632 * perform proper recovery as desired.
2635 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
2636 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2638 static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
2639 pci_channel_state_t state)
2641 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2642 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2643 struct lpfc_sli *psli = &phba->sli;
2644 struct lpfc_sli_ring *pring;
2646 if (state == pci_channel_io_perm_failure)
2647 return PCI_ERS_RESULT_DISCONNECT;
2649 pci_disable_device(pdev);
2651 * There may be I/Os dropped by the firmware.
2652 * Error iocb (I/O) on txcmplq and let the SCSI layer
2653 * retry it after re-establishing link.
2655 pring = &psli->ring[psli->fcp_ring];
2656 lpfc_sli_abort_iocb_ring(phba, pring);
2658 if (phba->intr_type == MSIX)
2659 lpfc_disable_msix(phba);
2661 free_irq(phba->pcidev->irq, phba);
2662 if (phba->intr_type == MSI)
2663 pci_disable_msi(phba->pcidev);
2666 /* Request a slot reset. */
2667 return PCI_ERS_RESULT_NEED_RESET;
2671 * lpfc_io_slot_reset: Restart a PCI device from scratch.
2672 * @pdev: pointer to PCI device.
2674 * This routine is registered to the PCI subsystem for error handling. This is
2675 * called after PCI bus has been reset to restart the PCI card from scratch,
2676 * as if from a cold-boot. During the PCI subsystem error recovery, after the
2677 * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform
2678 * proper error recovery and then call this routine before calling the .resume
2679 * method to recover the device. This function will initialize the HBA device,
2680 * enable the interrupt, but it will just put the HBA to offline state without
2681 * passing any I/O traffic.
2684 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
2685 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
2687 static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
2689 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2690 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2691 struct lpfc_sli *psli = &phba->sli;
2694 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
2695 if (pci_enable_device_mem(pdev)) {
2696 printk(KERN_ERR "lpfc: Cannot re-enable "
2697 "PCI device after reset.\n");
2698 return PCI_ERS_RESULT_DISCONNECT;
2701 pci_set_master(pdev);
2703 spin_lock_irq(&phba->hbalock);
2704 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2705 spin_unlock_irq(&phba->hbalock);
2707 /* Enable configured interrupt method */
2708 phba->intr_type = NONE;
2709 if (phba->cfg_use_msi == 2) {
2710 error = lpfc_enable_msix(phba);
2712 phba->intr_type = MSIX;
2715 /* Fallback to MSI if MSI-X initialization failed */
2716 if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) {
2717 retval = pci_enable_msi(phba->pcidev);
2719 phba->intr_type = MSI;
2721 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2722 "0470 Enable MSI failed, continuing "
2726 /* MSI-X is the only case the doesn't need to call request_irq */
2727 if (phba->intr_type != MSIX) {
2728 retval = request_irq(phba->pcidev->irq, lpfc_intr_handler,
2729 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
2731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2732 "0471 Enable interrupt handler "
2734 } else if (phba->intr_type != MSI)
2735 phba->intr_type = INTx;
2738 /* Take device offline; this will perform cleanup */
2740 lpfc_sli_brdrestart(phba);
2742 return PCI_ERS_RESULT_RECOVERED;
2746 * lpfc_io_resume: Resume PCI I/O operation.
2747 * @pdev: pointer to PCI device
2749 * This routine is registered to the PCI subsystem for error handling. It is
2750 * called when kernel error recovery tells the lpfc driver that it is ok to
2751 * resume normal PCI operation after PCI bus error recovery. After this call,
2752 * traffic can start to flow from this device again.
2754 static void lpfc_io_resume(struct pci_dev *pdev)
2756 struct Scsi_Host *shost = pci_get_drvdata(pdev);
2757 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2762 static struct pci_device_id lpfc_id_table[] = {
2763 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
2764 PCI_ANY_ID, PCI_ANY_ID, },
2765 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
2766 PCI_ANY_ID, PCI_ANY_ID, },
2767 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
2768 PCI_ANY_ID, PCI_ANY_ID, },
2769 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
2770 PCI_ANY_ID, PCI_ANY_ID, },
2771 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
2772 PCI_ANY_ID, PCI_ANY_ID, },
2773 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
2774 PCI_ANY_ID, PCI_ANY_ID, },
2775 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
2776 PCI_ANY_ID, PCI_ANY_ID, },
2777 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
2778 PCI_ANY_ID, PCI_ANY_ID, },
2779 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
2780 PCI_ANY_ID, PCI_ANY_ID, },
2781 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
2782 PCI_ANY_ID, PCI_ANY_ID, },
2783 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
2784 PCI_ANY_ID, PCI_ANY_ID, },
2785 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
2786 PCI_ANY_ID, PCI_ANY_ID, },
2787 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
2788 PCI_ANY_ID, PCI_ANY_ID, },
2789 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
2790 PCI_ANY_ID, PCI_ANY_ID, },
2791 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
2792 PCI_ANY_ID, PCI_ANY_ID, },
2793 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
2794 PCI_ANY_ID, PCI_ANY_ID, },
2795 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
2796 PCI_ANY_ID, PCI_ANY_ID, },
2797 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
2798 PCI_ANY_ID, PCI_ANY_ID, },
2799 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
2800 PCI_ANY_ID, PCI_ANY_ID, },
2801 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
2802 PCI_ANY_ID, PCI_ANY_ID, },
2803 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
2804 PCI_ANY_ID, PCI_ANY_ID, },
2805 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
2806 PCI_ANY_ID, PCI_ANY_ID, },
2807 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
2808 PCI_ANY_ID, PCI_ANY_ID, },
2809 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
2810 PCI_ANY_ID, PCI_ANY_ID, },
2811 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
2812 PCI_ANY_ID, PCI_ANY_ID, },
2813 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
2814 PCI_ANY_ID, PCI_ANY_ID, },
2815 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
2816 PCI_ANY_ID, PCI_ANY_ID, },
2817 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
2818 PCI_ANY_ID, PCI_ANY_ID, },
2819 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
2820 PCI_ANY_ID, PCI_ANY_ID, },
2821 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
2822 PCI_ANY_ID, PCI_ANY_ID, },
2823 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
2824 PCI_ANY_ID, PCI_ANY_ID, },
2825 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
2826 PCI_ANY_ID, PCI_ANY_ID, },
2827 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
2828 PCI_ANY_ID, PCI_ANY_ID, },
2832 MODULE_DEVICE_TABLE(pci, lpfc_id_table);
2834 static struct pci_error_handlers lpfc_err_handler = {
2835 .error_detected = lpfc_io_error_detected,
2836 .slot_reset = lpfc_io_slot_reset,
2837 .resume = lpfc_io_resume,
2840 static struct pci_driver lpfc_driver = {
2841 .name = LPFC_DRIVER_NAME,
2842 .id_table = lpfc_id_table,
2843 .probe = lpfc_pci_probe_one,
2844 .remove = __devexit_p(lpfc_pci_remove_one),
2845 .err_handler = &lpfc_err_handler,
2849 * lpfc_init: lpfc module initialization routine.
2851 * This routine is to be invoked when the lpfc module is loaded into the
2852 * kernel. The special kernel macro module_init() is used to indicate the
2853 * role of this routine to the kernel as lpfc module entry point.
2857 * -ENOMEM - FC attach transport failed
2858 * all others - failed
2865 printk(LPFC_MODULE_DESC "\n");
2866 printk(LPFC_COPYRIGHT "\n");
2868 if (lpfc_enable_npiv) {
2869 lpfc_transport_functions.vport_create = lpfc_vport_create;
2870 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
2872 lpfc_transport_template =
2873 fc_attach_transport(&lpfc_transport_functions);
2874 if (lpfc_transport_template == NULL)
2876 if (lpfc_enable_npiv) {
2877 lpfc_vport_transport_template =
2878 fc_attach_transport(&lpfc_vport_transport_functions);
2879 if (lpfc_vport_transport_template == NULL) {
2880 fc_release_transport(lpfc_transport_template);
2884 error = pci_register_driver(&lpfc_driver);
2886 fc_release_transport(lpfc_transport_template);
2887 if (lpfc_enable_npiv)
2888 fc_release_transport(lpfc_vport_transport_template);
2895 * lpfc_exit: lpfc module removal routine.
2897 * This routine is invoked when the lpfc module is removed from the kernel.
2898 * The special kernel macro module_exit() is used to indicate the role of
2899 * this routine to the kernel as lpfc module exit point.
2904 pci_unregister_driver(&lpfc_driver);
2905 fc_release_transport(lpfc_transport_template);
2906 if (lpfc_enable_npiv)
2907 fc_release_transport(lpfc_vport_transport_template);
2910 module_init(lpfc_init);
2911 module_exit(lpfc_exit);
2912 MODULE_LICENSE("GPL");
2913 MODULE_DESCRIPTION(LPFC_MODULE_DESC);
2914 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
2915 MODULE_VERSION("0:" LPFC_DRIVER_VERSION);