|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* | 
|  | 2 | * This file is part of the Emulex Linux Device Driver for         * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters.                                * | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Emulex.  All rights reserved.           * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex.                        * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com                                                  * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig              * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | *                                                                 * | 
|  | 9 | * This program is free software; you can redistribute it and/or   * | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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.                                     * | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ | 
|  | 21 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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> | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 30 | #include <linux/ctype.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 |  | 
| James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #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 Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 39 | #include "lpfc_nl.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_disc.h" | 
|  | 41 | #include "lpfc_scsi.h" | 
|  | 42 | #include "lpfc.h" | 
|  | 43 | #include "lpfc_logmsg.h" | 
|  | 44 | #include "lpfc_crtn.h" | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 45 | #include "lpfc_vport.h" | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_version.h" | 
|  | 47 |  | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 48 | char *_dump_buf_data; | 
|  | 49 | unsigned long _dump_buf_data_order; | 
|  | 50 | char *_dump_buf_dif; | 
|  | 51 | unsigned long _dump_buf_dif_order; | 
|  | 52 | spinlock_t _dump_buf_lock; | 
|  | 53 |  | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 54 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); | 
|  | 56 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | 
|  | 57 |  | 
|  | 58 | static struct scsi_transport_template *lpfc_transport_template = NULL; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 59 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | static DEFINE_IDR(lpfc_hba_index); | 
|  | 61 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 62 | /** | 
|  | 63 | * lpfc_config_port_prep: Perform lpfc initialization prior to config port. | 
|  | 64 | * @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 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 76 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 77 | lpfc_config_port_prep(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | { | 
|  | 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 Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 87 | static int init_key = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 |  | 
|  | 89 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 90 | if (!pmb) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 91 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 92 | return -ENOMEM; | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | mb = &pmb->mb; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 96 | phba->link_state = LPFC_INIT_MBX_CMDS; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 97 |  | 
|  | 98 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 99 | if (init_key) { | 
|  | 100 | uint32_t *ptext = (uint32_t *) licensed; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 |  | 
| James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 102 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) | 
|  | 103 | *ptext = cpu_to_be32(*ptext); | 
|  | 104 | init_key = 0; | 
|  | 105 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 |  | 
|  | 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 Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 116 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 117 | "0324 Config Port initialization " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | "error, mbxCmd x%x READ_NVPARM, " | 
|  | 119 | "mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | 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 Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 125 | sizeof(phba->wwnn)); | 
|  | 126 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | 
|  | 127 | sizeof(phba->wwpn)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 130 | phba->sli3_options = 0x0; | 
|  | 131 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | /* 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 Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 137 | "0439 Adapter failed to init, mbxCmd x%x " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 138 | "READ_REV, mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 139 | mb->mbxCommand, mb->mbxStatus); | 
|  | 140 | mempool_free( pmb, phba->mbox_mem_pool); | 
|  | 141 | return -ERESTART; | 
|  | 142 | } | 
|  | 143 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 144 |  | 
| James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 145 | /* | 
|  | 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. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 148 | */ | 
| James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 149 | if (mb->un.varRdRev.rr == 0) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 150 | vp->rev.rBit = 0; | 
| James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 152 | "0440 Adapter failed to init, READ_REV has " | 
|  | 153 | "missing revision information.\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 154 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 155 | return -ERESTART; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 158 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { | 
|  | 159 | mempool_free(pmb, phba->mbox_mem_pool); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 160 | return -EINVAL; | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 161 | } | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 162 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | /* Save information as VPD data */ | 
| James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 164 | vp->rev.rBit = 1; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 165 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); | 
| James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 166 | 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); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 170 | 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 Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 181 | /* 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 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 188 | if (lpfc_is_LC_HBA(phba->pcidev->device)) | 
|  | 189 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | 
|  | 190 | sizeof (phba->RandomData)); | 
|  | 191 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 192 | /* Get adapter VPD information */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); | 
|  | 194 | if (!lpfc_vpd_data) | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 195 | goto out_free_mbox; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 |  | 
|  | 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 Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 203 | "0441 VPD not present on adapter, " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 205 | mb->mbxCommand, mb->mbxStatus); | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 206 | mb->un.varDmp.word_cnt = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | } | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 208 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) | 
|  | 209 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 210 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | 
|  | 211 | lpfc_vpd_data + offset, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 212 | mb->un.varDmp.word_cnt); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 213 | offset += mb->un.varDmp.word_cnt; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 214 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); | 
|  | 215 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 216 |  | 
|  | 217 | kfree(lpfc_vpd_data); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 218 | out_free_mbox: | 
|  | 219 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 220 | return 0; | 
|  | 221 | } | 
|  | 222 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 223 | /** | 
|  | 224 | * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd. | 
|  | 225 | * @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 Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 233 | static void | 
|  | 234 | lpfc_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 Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 244 | /** | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 245 | * lpfc_dump_wakeup_param_cmpl: Completion handler for dump memory mailbox | 
|  | 246 | *     command used for getting wake up parameters. | 
|  | 247 | * @phba: pointer to lpfc hba data structure. | 
|  | 248 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | 
|  | 249 | * | 
|  | 250 | * This is the completion handler for dump mailbox command for getting | 
|  | 251 | * wake up parameters. When this command complete, the response contain | 
|  | 252 | * Option rom version of the HBA. This function translate the version number | 
|  | 253 | * into a human readable string and store it in OptionROMVersion. | 
|  | 254 | **/ | 
|  | 255 | static void | 
|  | 256 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | 
|  | 257 | { | 
|  | 258 | struct prog_id *prg; | 
|  | 259 | uint32_t prog_id_word; | 
|  | 260 | char dist = ' '; | 
|  | 261 | /* character array used for decoding dist type. */ | 
|  | 262 | char dist_char[] = "nabx"; | 
|  | 263 |  | 
| James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 264 | if (pmboxq->mb.mbxStatus != MBX_SUCCESS) { | 
|  | 265 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 266 | return; | 
| James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 267 | } | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 268 |  | 
|  | 269 | prg = (struct prog_id *) &prog_id_word; | 
|  | 270 |  | 
|  | 271 | /* word 7 contain option rom version */ | 
|  | 272 | prog_id_word = pmboxq->mb.un.varWords[7]; | 
|  | 273 |  | 
|  | 274 | /* Decode the Option rom version word to a readable string */ | 
|  | 275 | if (prg->dist < 4) | 
|  | 276 | dist = dist_char[prg->dist]; | 
|  | 277 |  | 
|  | 278 | if ((prg->dist == 3) && (prg->num == 0)) | 
|  | 279 | sprintf(phba->OptionROMVersion, "%d.%d%d", | 
|  | 280 | prg->ver, prg->rev, prg->lev); | 
|  | 281 | else | 
|  | 282 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | 
|  | 283 | prg->ver, prg->rev, prg->lev, | 
|  | 284 | dist, prg->num); | 
| James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 285 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 286 | return; | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 290 | * lpfc_config_port_post: Perform lpfc initialization after config port. | 
|  | 291 | * @phba: pointer to lpfc hba data structure. | 
|  | 292 | * | 
|  | 293 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | 
|  | 294 | * command call. It performs all internal resource and state setups on the | 
|  | 295 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | 
|  | 296 | * ELS ring timers, etc. | 
|  | 297 | * | 
|  | 298 | * Return codes | 
|  | 299 | *   0 - success. | 
|  | 300 | *   Any other value - error. | 
|  | 301 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 302 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 303 | lpfc_config_port_post(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 304 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 305 | struct lpfc_vport *vport = phba->pport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 306 | 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 Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 311 | int i, j; | 
|  | 312 | int rc; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 313 |  | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 314 | 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 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 323 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 324 | if (!pmb) { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 325 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 326 | return -ENOMEM; | 
|  | 327 | } | 
|  | 328 | mb = &pmb->mb; | 
|  | 329 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | /* Get login parameters for NID.  */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 331 | lpfc_read_sparam(phba, pmb, 0); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 332 | pmb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 335 | "0448 Adapter failed init, mbxCmd x%x " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 336 | "READ_SPARM mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 337 | mb->mbxCommand, mb->mbxStatus); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 338 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 339 | 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 Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 348 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 349 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 350 | kfree(mp); | 
|  | 351 | pmb->context1 = NULL; | 
|  | 352 |  | 
| James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 353 | if (phba->cfg_soft_wwnn) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 354 | u64_to_wwn(phba->cfg_soft_wwnn, | 
|  | 355 | vport->fc_sparam.nodeName.u.wwn); | 
| James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 356 | if (phba->cfg_soft_wwpn) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 357 | u64_to_wwn(phba->cfg_soft_wwpn, | 
|  | 358 | vport->fc_sparam.portName.u.wwn); | 
|  | 359 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 360 | sizeof (struct lpfc_name)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 361 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 362 | sizeof (struct lpfc_name)); | 
|  | 363 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ | 
|  | 364 | /* This should be consolidated into parse_vpd ? - mr */ | 
|  | 365 | if (phba->SerialNumber[0] == 0) { | 
|  | 366 | uint8_t *outptr; | 
|  | 367 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 368 | outptr = &vport->fc_nodename.u.s.IEEE[0]; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 369 | for (i = 0; i < 12; i++) { | 
|  | 370 | status = *outptr++; | 
|  | 371 | j = ((status & 0xf0) >> 4); | 
|  | 372 | if (j <= 9) | 
|  | 373 | phba->SerialNumber[i] = | 
|  | 374 | (char)((uint8_t) 0x30 + (uint8_t) j); | 
|  | 375 | else | 
|  | 376 | phba->SerialNumber[i] = | 
|  | 377 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | 
|  | 378 | i++; | 
|  | 379 | j = (status & 0xf); | 
|  | 380 | if (j <= 9) | 
|  | 381 | phba->SerialNumber[i] = | 
|  | 382 | (char)((uint8_t) 0x30 + (uint8_t) j); | 
|  | 383 | else | 
|  | 384 | phba->SerialNumber[i] = | 
|  | 385 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | 
|  | 386 | } | 
|  | 387 | } | 
|  | 388 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 389 | lpfc_read_config(phba, pmb); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 390 | pmb->vport = vport; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 391 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 392 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 393 | "0453 Adapter failed to init, mbxCmd x%x " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 394 | "READ_CONFIG, mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 395 | mb->mbxCommand, mb->mbxStatus); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 396 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 397 | mempool_free( pmb, phba->mbox_mem_pool); | 
|  | 398 | return -EIO; | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 | /* Reset the DFT_HBA_Q_DEPTH to the max xri  */ | 
|  | 402 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | 
|  | 403 | phba->cfg_hba_queue_depth = | 
|  | 404 | mb->un.varRdConfig.max_xri + 1; | 
|  | 405 |  | 
|  | 406 | phba->lmt = mb->un.varRdConfig.lmt; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 407 |  | 
|  | 408 | /* Get the default values for Model Name and Description */ | 
|  | 409 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | 
|  | 410 |  | 
|  | 411 | if ((phba->cfg_link_speed > LINK_SPEED_10G) | 
|  | 412 | || ((phba->cfg_link_speed == LINK_SPEED_1G) | 
|  | 413 | && !(phba->lmt & LMT_1Gb)) | 
|  | 414 | || ((phba->cfg_link_speed == LINK_SPEED_2G) | 
|  | 415 | && !(phba->lmt & LMT_2Gb)) | 
|  | 416 | || ((phba->cfg_link_speed == LINK_SPEED_4G) | 
|  | 417 | && !(phba->lmt & LMT_4Gb)) | 
|  | 418 | || ((phba->cfg_link_speed == LINK_SPEED_8G) | 
|  | 419 | && !(phba->lmt & LMT_8Gb)) | 
|  | 420 | || ((phba->cfg_link_speed == LINK_SPEED_10G) | 
|  | 421 | && !(phba->lmt & LMT_10Gb))) { | 
|  | 422 | /* Reset link speed to auto */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 423 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 424 | "1302 Invalid speed for this board: " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | "Reset link speed to auto: x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | phba->cfg_link_speed); | 
|  | 427 | phba->cfg_link_speed = LINK_SPEED_AUTO; | 
|  | 428 | } | 
|  | 429 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 430 | phba->link_state = LPFC_LINK_DOWN; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 |  | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 432 | /* Only process IOCBs on ELS ring till hba_state is READY */ | 
| James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 433 | if (psli->ring[psli->extra_ring].cmdringaddr) | 
|  | 434 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | if (psli->ring[psli->fcp_ring].cmdringaddr) | 
|  | 436 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | 
|  | 437 | if (psli->ring[psli->next_ring].cmdringaddr) | 
|  | 438 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | 
|  | 439 |  | 
|  | 440 | /* Post receive buffers for desired rings */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 441 | if (phba->sli_rev != 3) | 
|  | 442 | lpfc_post_rcv_buf(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 444 | /* | 
|  | 445 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | 
|  | 446 | */ | 
|  | 447 | if (phba->intr_type == MSIX) { | 
|  | 448 | rc = lpfc_config_msi(phba, pmb); | 
|  | 449 | if (rc) { | 
|  | 450 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 451 | return -EIO; | 
|  | 452 | } | 
|  | 453 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | 
|  | 454 | if (rc != MBX_SUCCESS) { | 
|  | 455 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | 
|  | 456 | "0352 Config MSI mailbox command " | 
|  | 457 | "failed, mbxCmd x%x, mbxStatus x%x\n", | 
|  | 458 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); | 
|  | 459 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 460 | return -EIO; | 
|  | 461 | } | 
|  | 462 | } | 
|  | 463 |  | 
|  | 464 | /* Initialize ERATT handling flag */ | 
|  | 465 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | 
|  | 466 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 467 | /* Enable appropriate host interrupts */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 468 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 469 | status = readl(phba->HCregaddr); | 
|  | 470 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; | 
|  | 471 | if (psli->num_rings > 0) | 
|  | 472 | status |= HC_R0INT_ENA; | 
|  | 473 | if (psli->num_rings > 1) | 
|  | 474 | status |= HC_R1INT_ENA; | 
|  | 475 | if (psli->num_rings > 2) | 
|  | 476 | status |= HC_R2INT_ENA; | 
|  | 477 | if (psli->num_rings > 3) | 
|  | 478 | status |= HC_R3INT_ENA; | 
|  | 479 |  | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 480 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && | 
|  | 481 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 482 | status &= ~(HC_R0INT_ENA); | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 483 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 484 | writel(status, phba->HCregaddr); | 
|  | 485 | readl(phba->HCregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 486 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 487 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 488 | /* Set up ring-0 (ELS) timer */ | 
|  | 489 | timeout = phba->fc_ratov * 2; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 490 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 491 | /* Set up heart beat (HB) timer */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 492 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | 
|  | 493 | phba->hb_outstanding = 0; | 
|  | 494 | phba->last_completion_time = jiffies; | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 495 | /* Set up error attention (ERATT) polling timer */ | 
|  | 496 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 497 |  | 
|  | 498 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); | 
|  | 499 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 
| James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 500 | lpfc_set_loopback_flag(phba); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 501 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 
| James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 502 | if (rc != MBX_SUCCESS) { | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 504 | "0454 Adapter failed to init, mbxCmd x%x " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | "INIT_LINK, mbxStatus x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | mb->mbxCommand, mb->mbxStatus); | 
|  | 507 |  | 
|  | 508 | /* Clear all interrupt enable conditions */ | 
|  | 509 | writel(0, phba->HCregaddr); | 
|  | 510 | readl(phba->HCregaddr); /* flush */ | 
|  | 511 | /* Clear all pending interrupts */ | 
|  | 512 | writel(0xffffffff, phba->HAregaddr); | 
|  | 513 | readl(phba->HAregaddr); /* flush */ | 
|  | 514 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 515 | phba->link_state = LPFC_HBA_ERROR; | 
| James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 516 | if (rc != MBX_BUSY) | 
|  | 517 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | return -EIO; | 
|  | 519 | } | 
|  | 520 | /* MBOX buffer will be freed in mbox compl */ | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 521 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 522 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); | 
|  | 523 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | 
|  | 524 | pmb->vport = phba->pport; | 
|  | 525 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 526 |  | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 527 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | 
|  | 528 | lpfc_printf_log(phba, | 
|  | 529 | KERN_ERR, | 
|  | 530 | LOG_INIT, | 
|  | 531 | "0456 Adapter failed to issue " | 
|  | 532 | "ASYNCEVT_ENABLE mbox status x%x \n.", | 
|  | 533 | rc); | 
|  | 534 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 535 | } | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 536 |  | 
|  | 537 | /* Get Option rom version */ | 
|  | 538 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 539 | lpfc_dump_wakeup_param(phba, pmb); | 
|  | 540 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | 
|  | 541 | pmb->vport = phba->pport; | 
|  | 542 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 
|  | 543 |  | 
|  | 544 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | 
|  | 545 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | 
|  | 546 | "to get Option ROM version status x%x\n.", rc); | 
|  | 547 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 548 | } | 
|  | 549 |  | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 550 | return 0; | 
| James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 551 | } | 
|  | 552 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 553 | /** | 
|  | 554 | * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset. | 
|  | 555 | * @phba: pointer to lpfc HBA data structure. | 
|  | 556 | * | 
|  | 557 | * This routine will do LPFC uninitialization before the HBA is reset when | 
|  | 558 | * bringing down the SLI Layer. | 
|  | 559 | * | 
|  | 560 | * Return codes | 
|  | 561 | *   0 - success. | 
|  | 562 | *   Any other value - error. | 
|  | 563 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 565 | lpfc_hba_down_prep(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 566 | { | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 567 | struct lpfc_vport **vports; | 
|  | 568 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | /* Disable interrupts */ | 
|  | 570 | writel(0, phba->HCregaddr); | 
|  | 571 | readl(phba->HCregaddr); /* flush */ | 
|  | 572 |  | 
| James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 573 | if (phba->pport->load_flag & FC_UNLOADING) | 
|  | 574 | lpfc_cleanup_discovery_resources(phba->pport); | 
|  | 575 | else { | 
|  | 576 | vports = lpfc_create_vport_work_array(phba); | 
|  | 577 | if (vports != NULL) | 
|  | 578 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) | 
|  | 579 | lpfc_cleanup_discovery_resources(vports[i]); | 
|  | 580 | lpfc_destroy_vport_work_array(phba, vports); | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 581 | } | 
|  | 582 | return 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | } | 
|  | 584 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 585 | /** | 
|  | 586 | * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset. | 
|  | 587 | * @phba: pointer to lpfc HBA data structure. | 
|  | 588 | * | 
|  | 589 | * This routine will do uninitialization after the HBA is reset when bring | 
|  | 590 | * down the SLI Layer. | 
|  | 591 | * | 
|  | 592 | * Return codes | 
|  | 593 | *   0 - sucess. | 
|  | 594 | *   Any other value - error. | 
|  | 595 | **/ | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 596 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 597 | lpfc_hba_down_post(struct lpfc_hba *phba) | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 598 | { | 
|  | 599 | struct lpfc_sli *psli = &phba->sli; | 
|  | 600 | struct lpfc_sli_ring *pring; | 
|  | 601 | struct lpfc_dmabuf *mp, *next_mp; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 602 | struct lpfc_iocbq *iocb; | 
|  | 603 | IOCB_t *cmd = NULL; | 
|  | 604 | LIST_HEAD(completions); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 605 | int i; | 
|  | 606 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 607 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) | 
|  | 608 | lpfc_sli_hbqbuf_free_all(phba); | 
|  | 609 | else { | 
|  | 610 | /* Cleanup preposted buffers on the ELS ring */ | 
|  | 611 | pring = &psli->ring[LPFC_ELS_RING]; | 
|  | 612 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | 
|  | 613 | list_del(&mp->list); | 
|  | 614 | pring->postbufq_cnt--; | 
|  | 615 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | 616 | kfree(mp); | 
|  | 617 | } | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 618 | } | 
|  | 619 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 620 | spin_lock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 621 | for (i = 0; i < psli->num_rings; i++) { | 
|  | 622 | pring = &psli->ring[i]; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 623 |  | 
|  | 624 | /* At this point in time the HBA is either reset or DOA. Either | 
|  | 625 | * way, nothing should be on txcmplq as it will NEVER complete. | 
|  | 626 | */ | 
|  | 627 | list_splice_init(&pring->txcmplq, &completions); | 
|  | 628 | pring->txcmplq_cnt = 0; | 
|  | 629 | spin_unlock_irq(&phba->hbalock); | 
|  | 630 |  | 
|  | 631 | while (!list_empty(&completions)) { | 
|  | 632 | iocb = list_get_first(&completions, struct lpfc_iocbq, | 
|  | 633 | list); | 
|  | 634 | cmd = &iocb->iocb; | 
|  | 635 | list_del_init(&iocb->list); | 
|  | 636 |  | 
|  | 637 | if (!iocb->iocb_cmpl) | 
|  | 638 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | 639 | else { | 
|  | 640 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | 
|  | 641 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | 
|  | 642 | (iocb->iocb_cmpl) (phba, iocb, iocb); | 
|  | 643 | } | 
|  | 644 | } | 
|  | 645 |  | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 646 | lpfc_sli_abort_iocb_ring(phba, pring); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 647 | spin_lock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 648 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 649 | spin_unlock_irq(&phba->hbalock); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 650 |  | 
|  | 651 | return 0; | 
|  | 652 | } | 
|  | 653 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 654 | /** | 
|  | 655 | * lpfc_hb_timeout: The HBA-timer timeout handler. | 
|  | 656 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | 
|  | 657 | * | 
|  | 658 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | 
|  | 659 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | 
|  | 660 | * work-port-events bitmap and the worker thread is notified. This timeout | 
|  | 661 | * event will be used by the worker thread to invoke the actual timeout | 
|  | 662 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | 
|  | 663 | * be performed in the timeout handler and the HBA timeout event bit shall | 
|  | 664 | * be cleared by the worker thread after it has taken the event bitmap out. | 
|  | 665 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 666 | static void | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 667 | lpfc_hb_timeout(unsigned long ptr) | 
|  | 668 | { | 
|  | 669 | struct lpfc_hba *phba; | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 670 | uint32_t tmo_posted; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 671 | unsigned long iflag; | 
|  | 672 |  | 
|  | 673 | phba = (struct lpfc_hba *)ptr; | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 674 |  | 
|  | 675 | /* Check for heart beat timeout conditions */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 676 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 677 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; | 
|  | 678 | if (!tmo_posted) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 679 | phba->pport->work_port_events |= WORKER_HB_TMO; | 
|  | 680 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | 
|  | 681 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 682 | /* Tell the worker thread there is work to do */ | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 683 | if (!tmo_posted) | 
|  | 684 | lpfc_worker_wake_up(phba); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 685 | return; | 
|  | 686 | } | 
|  | 687 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 688 | /** | 
|  | 689 | * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function. | 
|  | 690 | * @phba: pointer to lpfc hba data structure. | 
|  | 691 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | 
|  | 692 | * | 
|  | 693 | * This is the callback function to the lpfc heart-beat mailbox command. | 
|  | 694 | * If configured, the lpfc driver issues the heart-beat mailbox command to | 
|  | 695 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | 
|  | 696 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | 
|  | 697 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | 
|  | 698 | * heart-beat outstanding state. Once the mailbox command comes back and | 
|  | 699 | * no error conditions detected, the heart-beat mailbox command timer is | 
|  | 700 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | 
|  | 701 | * state is cleared for the next heart-beat. If the timer expired with the | 
|  | 702 | * heart-beat outstanding state set, the driver will put the HBA offline. | 
|  | 703 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 704 | static void | 
|  | 705 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | 
|  | 706 | { | 
|  | 707 | unsigned long drvr_flag; | 
|  | 708 |  | 
|  | 709 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | 
|  | 710 | phba->hb_outstanding = 0; | 
|  | 711 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 
|  | 712 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 713 | /* Check and reset heart-beat timer is necessary */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 714 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 715 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | 
|  | 716 | !(phba->link_state == LPFC_HBA_ERROR) && | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 717 | !(phba->pport->load_flag & FC_UNLOADING)) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 718 | mod_timer(&phba->hb_tmofunc, | 
|  | 719 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | 
|  | 720 | return; | 
|  | 721 | } | 
|  | 722 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 723 | /** | 
|  | 724 | * lpfc_hb_timeout_handler: The HBA-timer timeout handler. | 
|  | 725 | * @phba: pointer to lpfc hba data structure. | 
|  | 726 | * | 
|  | 727 | * This is the actual HBA-timer timeout handler to be invoked by the worker | 
|  | 728 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | 
|  | 729 | * handler performs any periodic operations needed for the device. If such | 
|  | 730 | * periodic event has already been attended to either in the interrupt handler | 
|  | 731 | * or by processing slow-ring or fast-ring events within the HBA-timer | 
|  | 732 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | 
|  | 733 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | 
|  | 734 | * is configured and there is no heart-beat mailbox command outstanding, a | 
|  | 735 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | 
|  | 736 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | 
|  | 737 | * to offline. | 
|  | 738 | **/ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 739 | void | 
|  | 740 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | 
|  | 741 | { | 
|  | 742 | LPFC_MBOXQ_t *pmboxq; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 743 | struct lpfc_dmabuf *buf_ptr; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 744 | int retval; | 
|  | 745 | struct lpfc_sli *psli = &phba->sli; | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 746 | LIST_HEAD(completions); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 747 |  | 
|  | 748 | if ((phba->link_state == LPFC_HBA_ERROR) || | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 749 | (phba->pport->load_flag & FC_UNLOADING) || | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 750 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) | 
|  | 751 | return; | 
|  | 752 |  | 
|  | 753 | spin_lock_irq(&phba->pport->work_port_lock); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 754 |  | 
|  | 755 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | 
|  | 756 | jiffies)) { | 
|  | 757 | spin_unlock_irq(&phba->pport->work_port_lock); | 
|  | 758 | if (!phba->hb_outstanding) | 
|  | 759 | mod_timer(&phba->hb_tmofunc, | 
|  | 760 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | 
|  | 761 | else | 
|  | 762 | mod_timer(&phba->hb_tmofunc, | 
|  | 763 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | 
|  | 764 | return; | 
|  | 765 | } | 
|  | 766 | spin_unlock_irq(&phba->pport->work_port_lock); | 
|  | 767 |  | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 768 | if (phba->elsbuf_cnt && | 
|  | 769 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | 
|  | 770 | spin_lock_irq(&phba->hbalock); | 
|  | 771 | list_splice_init(&phba->elsbuf, &completions); | 
|  | 772 | phba->elsbuf_cnt = 0; | 
|  | 773 | phba->elsbuf_prev_cnt = 0; | 
|  | 774 | spin_unlock_irq(&phba->hbalock); | 
|  | 775 |  | 
|  | 776 | while (!list_empty(&completions)) { | 
|  | 777 | list_remove_head(&completions, buf_ptr, | 
|  | 778 | struct lpfc_dmabuf, list); | 
|  | 779 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | 
|  | 780 | kfree(buf_ptr); | 
|  | 781 | } | 
|  | 782 | } | 
|  | 783 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | 
|  | 784 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 785 | /* If there is no heart beat outstanding, issue a heartbeat command */ | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 786 | if (phba->cfg_enable_hba_heartbeat) { | 
|  | 787 | if (!phba->hb_outstanding) { | 
|  | 788 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | 
|  | 789 | if (!pmboxq) { | 
|  | 790 | mod_timer(&phba->hb_tmofunc, | 
|  | 791 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | 
|  | 792 | return; | 
|  | 793 | } | 
|  | 794 |  | 
|  | 795 | lpfc_heart_beat(phba, pmboxq); | 
|  | 796 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | 
|  | 797 | pmboxq->vport = phba->pport; | 
|  | 798 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | 
|  | 799 |  | 
|  | 800 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { | 
|  | 801 | mempool_free(pmboxq, phba->mbox_mem_pool); | 
|  | 802 | mod_timer(&phba->hb_tmofunc, | 
|  | 803 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | 
|  | 804 | return; | 
|  | 805 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 806 | mod_timer(&phba->hb_tmofunc, | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 807 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | 
|  | 808 | phba->hb_outstanding = 1; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 809 | return; | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 810 | } else { | 
|  | 811 | /* | 
|  | 812 | * If heart beat timeout called with hb_outstanding set | 
|  | 813 | * we need to take the HBA offline. | 
|  | 814 | */ | 
|  | 815 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 816 | "0459 Adapter heartbeat failure, " | 
|  | 817 | "taking this port offline.\n"); | 
|  | 818 |  | 
|  | 819 | spin_lock_irq(&phba->hbalock); | 
|  | 820 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
|  | 821 | spin_unlock_irq(&phba->hbalock); | 
|  | 822 |  | 
|  | 823 | lpfc_offline_prep(phba); | 
|  | 824 | lpfc_offline(phba); | 
|  | 825 | lpfc_unblock_mgmt_io(phba); | 
|  | 826 | phba->link_state = LPFC_HBA_ERROR; | 
|  | 827 | lpfc_hba_down_post(phba); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 828 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 829 | } | 
|  | 830 | } | 
|  | 831 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 832 | /** | 
|  | 833 | * lpfc_offline_eratt: Bring lpfc offline on hardware error attention. | 
|  | 834 | * @phba: pointer to lpfc hba data structure. | 
|  | 835 | * | 
|  | 836 | * This routine is called to bring the HBA offline when HBA hardware error | 
|  | 837 | * other than Port Error 6 has been detected. | 
|  | 838 | **/ | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 839 | static void | 
|  | 840 | lpfc_offline_eratt(struct lpfc_hba *phba) | 
|  | 841 | { | 
|  | 842 | struct lpfc_sli   *psli = &phba->sli; | 
|  | 843 |  | 
|  | 844 | spin_lock_irq(&phba->hbalock); | 
|  | 845 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
|  | 846 | spin_unlock_irq(&phba->hbalock); | 
|  | 847 | lpfc_offline_prep(phba); | 
|  | 848 |  | 
|  | 849 | lpfc_offline(phba); | 
|  | 850 | lpfc_reset_barrier(phba); | 
|  | 851 | lpfc_sli_brdreset(phba); | 
|  | 852 | lpfc_hba_down_post(phba); | 
|  | 853 | lpfc_sli_brdready(phba, HS_MBRDY); | 
|  | 854 | lpfc_unblock_mgmt_io(phba); | 
|  | 855 | phba->link_state = LPFC_HBA_ERROR; | 
|  | 856 | return; | 
|  | 857 | } | 
|  | 858 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 859 | /** | 
|  | 860 | * lpfc_handle_eratt: The HBA hardware error handler. | 
|  | 861 | * @phba: pointer to lpfc hba data structure. | 
|  | 862 | * | 
|  | 863 | * This routine is invoked to handle the following HBA hardware error | 
|  | 864 | * conditions: | 
|  | 865 | * 1 - HBA error attention interrupt | 
|  | 866 | * 2 - DMA ring index out of range | 
|  | 867 | * 3 - Mailbox command came back as unknown | 
|  | 868 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 869 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 870 | lpfc_handle_eratt(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 872 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 873 | struct lpfc_sli   *psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 874 | struct lpfc_sli_ring  *pring; | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 875 | uint32_t event_data; | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 876 | unsigned long temperature; | 
|  | 877 | struct temp_event temp_event_data; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 878 | struct Scsi_Host  *shost; | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 879 | struct lpfc_board_event_header board_event; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 880 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 881 | /* If the pci channel is offline, ignore possible errors, | 
|  | 882 | * since we cannot communicate with the pci card anyway. */ | 
|  | 883 | if (pci_channel_offline(phba->pcidev)) | 
|  | 884 | return; | 
| James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 885 | /* If resets are disabled then leave the HBA alone and return */ | 
|  | 886 | if (!phba->cfg_enable_hba_reset) | 
|  | 887 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 888 |  | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 889 | /* Send an internal error event to mgmt application */ | 
|  | 890 | board_event.event_type = FC_REG_BOARD_EVENT; | 
|  | 891 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | 
|  | 892 | shost = lpfc_shost_from_vport(phba->pport); | 
|  | 893 | fc_host_post_vendor_event(shost, fc_get_event_number(), | 
|  | 894 | sizeof(board_event), | 
|  | 895 | (char *) &board_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 896 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 897 |  | 
| James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 898 | if (phba->work_hs & HS_FFER6) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 899 | /* Re-establishing Link */ | 
|  | 900 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 901 | "1301 Re-establishing Link " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 902 | "Data: x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 903 | phba->work_hs, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 904 | phba->work_status[0], phba->work_status[1]); | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 905 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 906 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 907 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 908 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 909 |  | 
|  | 910 | /* | 
|  | 911 | * Firmware stops when it triggled erratt with HS_FFER6. | 
|  | 912 | * That could cause the I/Os dropped by the firmware. | 
|  | 913 | * Error iocb (I/O) on txcmplq and let the SCSI layer | 
|  | 914 | * retry it after re-establishing link. | 
|  | 915 | */ | 
|  | 916 | pring = &psli->ring[psli->fcp_ring]; | 
|  | 917 | lpfc_sli_abort_iocb_ring(phba, pring); | 
|  | 918 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | /* | 
|  | 920 | * There was a firmware error.  Take the hba offline and then | 
|  | 921 | * attempt to restart it. | 
|  | 922 | */ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 923 | lpfc_offline_prep(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | lpfc_offline(phba); | 
| Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 925 | lpfc_sli_brdrestart(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 926 | if (lpfc_online(phba) == 0) {	/* Initialize the HBA */ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 927 | lpfc_unblock_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 928 | return; | 
|  | 929 | } | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 930 | lpfc_unblock_mgmt_io(phba); | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 931 | } else if (phba->work_hs & HS_CRIT_TEMP) { | 
|  | 932 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | 
|  | 933 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | 
|  | 934 | temp_event_data.event_code = LPFC_CRIT_TEMP; | 
|  | 935 | temp_event_data.data = (uint32_t)temperature; | 
|  | 936 |  | 
|  | 937 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 938 | "0406 Adapter maximum temperature exceeded " | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 939 | "(%ld), taking this port offline " | 
|  | 940 | "Data: x%x x%x x%x\n", | 
|  | 941 | temperature, phba->work_hs, | 
|  | 942 | phba->work_status[0], phba->work_status[1]); | 
|  | 943 |  | 
|  | 944 | shost = lpfc_shost_from_vport(phba->pport); | 
|  | 945 | fc_host_post_vendor_event(shost, fc_get_event_number(), | 
|  | 946 | sizeof(temp_event_data), | 
|  | 947 | (char *) &temp_event_data, | 
|  | 948 | SCSI_NL_VID_TYPE_PCI | 
|  | 949 | | PCI_VENDOR_ID_EMULEX); | 
|  | 950 |  | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 951 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 952 | phba->over_temp_state = HBA_OVER_TEMP; | 
|  | 953 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 954 | lpfc_offline_eratt(phba); | 
| James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 955 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | } else { | 
|  | 957 | /* The if clause above forces this code path when the status | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 958 | * failure is a value other than FFER6. Do not call the offline | 
|  | 959 | * twice. This is the adapter hardware error path. | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | */ | 
|  | 961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 962 | "0457 Adapter Hardware Error " | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 963 | "Data: x%x x%x x%x\n", | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 964 | phba->work_hs, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 965 | phba->work_status[0], phba->work_status[1]); | 
|  | 966 |  | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 967 | event_data = FC_REG_DUMP_EVENT; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 968 | shost = lpfc_shost_from_vport(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 969 | fc_host_post_vendor_event(shost, fc_get_event_number(), | 
| James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 970 | sizeof(event_data), (char *) &event_data, | 
|  | 971 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | 
|  | 972 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 973 | lpfc_offline_eratt(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 974 | } | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 975 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | } | 
|  | 977 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 978 | /** | 
|  | 979 | * lpfc_handle_latt: The HBA link event handler. | 
|  | 980 | * @phba: pointer to lpfc hba data structure. | 
|  | 981 | * | 
|  | 982 | * This routine is invoked from the worker thread to handle a HBA host | 
|  | 983 | * attention link event. | 
|  | 984 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 985 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 986 | lpfc_handle_latt(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 988 | struct lpfc_vport *vport = phba->pport; | 
|  | 989 | struct lpfc_sli   *psli = &phba->sli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | LPFC_MBOXQ_t *pmb; | 
|  | 991 | volatile uint32_t control; | 
|  | 992 | struct lpfc_dmabuf *mp; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 993 | int rc = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 |  | 
|  | 995 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 996 | if (!pmb) { | 
|  | 997 | rc = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | goto lpfc_handle_latt_err_exit; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 999 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 |  | 
|  | 1001 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1002 | if (!mp) { | 
|  | 1003 | rc = 2; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1004 | goto lpfc_handle_latt_free_pmb; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1005 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 |  | 
|  | 1007 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1008 | if (!mp->virt) { | 
|  | 1009 | rc = 3; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | goto lpfc_handle_latt_free_mp; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1011 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 |  | 
| James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1013 | /* Cleanup any outstanding ELS commands */ | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1014 | lpfc_els_flush_all_cmd(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1015 |  | 
|  | 1016 | psli->slistat.link_event++; | 
|  | 1017 | lpfc_read_la(phba, pmb, mp); | 
|  | 1018 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1019 | pmb->vport = vport; | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1020 | /* Block ELS IOCBs until we have processed this mbox command */ | 
|  | 1021 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | 
| James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1022 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1023 | if (rc == MBX_NOT_FINISHED) { | 
|  | 1024 | rc = 4; | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1025 | goto lpfc_handle_latt_free_mbuf; | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1026 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1027 |  | 
|  | 1028 | /* Clear Link Attention in HA REG */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1029 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | writel(HA_LATT, phba->HAregaddr); | 
|  | 1031 | readl(phba->HAregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1032 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 |  | 
|  | 1034 | return; | 
|  | 1035 |  | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1036 | lpfc_handle_latt_free_mbuf: | 
| James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1037 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; | 
| James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1038 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | lpfc_handle_latt_free_mp: | 
|  | 1040 | kfree(mp); | 
|  | 1041 | lpfc_handle_latt_free_pmb: | 
| James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1042 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | lpfc_handle_latt_err_exit: | 
|  | 1044 | /* Enable Link attention interrupts */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1045 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1046 | psli->sli_flag |= LPFC_PROCESS_LA; | 
|  | 1047 | control = readl(phba->HCregaddr); | 
|  | 1048 | control |= HC_LAINT_ENA; | 
|  | 1049 | writel(control, phba->HCregaddr); | 
|  | 1050 | readl(phba->HCregaddr); /* flush */ | 
|  | 1051 |  | 
|  | 1052 | /* Clear Link Attention in HA REG */ | 
|  | 1053 | writel(HA_LATT, phba->HAregaddr); | 
|  | 1054 | readl(phba->HAregaddr); /* flush */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1055 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | lpfc_linkdown(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1057 | phba->link_state = LPFC_HBA_ERROR; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1058 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1059 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | 
|  | 1060 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1061 |  | 
|  | 1062 | return; | 
|  | 1063 | } | 
|  | 1064 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1065 | /** | 
|  | 1066 | * lpfc_parse_vpd: Parse VPD (Vital Product Data). | 
|  | 1067 | * @phba: pointer to lpfc hba data structure. | 
|  | 1068 | * @vpd: pointer to the vital product data. | 
|  | 1069 | * @len: length of the vital product data in bytes. | 
|  | 1070 | * | 
|  | 1071 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | 
|  | 1072 | * an array of characters. In this routine, the ModelName, ProgramType, and | 
|  | 1073 | * ModelDesc, etc. fields of the phba data structure will be populated. | 
|  | 1074 | * | 
|  | 1075 | * Return codes | 
|  | 1076 | *   0 - pointer to the VPD passed in is NULL | 
|  | 1077 | *   1 - success | 
|  | 1078 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1079 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1080 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1081 | { | 
|  | 1082 | uint8_t lenlo, lenhi; | 
| Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1083 | int Length; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | int i, j; | 
|  | 1085 | int finished = 0; | 
|  | 1086 | int index = 0; | 
|  | 1087 |  | 
|  | 1088 | if (!vpd) | 
|  | 1089 | return 0; | 
|  | 1090 |  | 
|  | 1091 | /* Vital Product */ | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1092 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1093 | "0455 Vital Product Data: x%x x%x x%x x%x\n", | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1094 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], | 
|  | 1095 | (uint32_t) vpd[3]); | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1096 | while (!finished && (index < (len - 4))) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1097 | switch (vpd[index]) { | 
|  | 1098 | case 0x82: | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1099 | case 0x91: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1100 | index += 1; | 
|  | 1101 | lenlo = vpd[index]; | 
|  | 1102 | index += 1; | 
|  | 1103 | lenhi = vpd[index]; | 
|  | 1104 | index += 1; | 
|  | 1105 | i = ((((unsigned short)lenhi) << 8) + lenlo); | 
|  | 1106 | index += i; | 
|  | 1107 | break; | 
|  | 1108 | case 0x90: | 
|  | 1109 | index += 1; | 
|  | 1110 | lenlo = vpd[index]; | 
|  | 1111 | index += 1; | 
|  | 1112 | lenhi = vpd[index]; | 
|  | 1113 | index += 1; | 
|  | 1114 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1115 | if (Length > len - index) | 
|  | 1116 | Length = len - index; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1117 | while (Length > 0) { | 
|  | 1118 | /* Look for Serial Number */ | 
|  | 1119 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | 
|  | 1120 | index += 2; | 
|  | 1121 | i = vpd[index]; | 
|  | 1122 | index += 1; | 
|  | 1123 | j = 0; | 
|  | 1124 | Length -= (3+i); | 
|  | 1125 | while(i--) { | 
|  | 1126 | phba->SerialNumber[j++] = vpd[index++]; | 
|  | 1127 | if (j == 31) | 
|  | 1128 | break; | 
|  | 1129 | } | 
|  | 1130 | phba->SerialNumber[j] = 0; | 
|  | 1131 | continue; | 
|  | 1132 | } | 
|  | 1133 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | 
|  | 1134 | phba->vpd_flag |= VPD_MODEL_DESC; | 
|  | 1135 | index += 2; | 
|  | 1136 | i = vpd[index]; | 
|  | 1137 | index += 1; | 
|  | 1138 | j = 0; | 
|  | 1139 | Length -= (3+i); | 
|  | 1140 | while(i--) { | 
|  | 1141 | phba->ModelDesc[j++] = vpd[index++]; | 
|  | 1142 | if (j == 255) | 
|  | 1143 | break; | 
|  | 1144 | } | 
|  | 1145 | phba->ModelDesc[j] = 0; | 
|  | 1146 | continue; | 
|  | 1147 | } | 
|  | 1148 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | 
|  | 1149 | phba->vpd_flag |= VPD_MODEL_NAME; | 
|  | 1150 | index += 2; | 
|  | 1151 | i = vpd[index]; | 
|  | 1152 | index += 1; | 
|  | 1153 | j = 0; | 
|  | 1154 | Length -= (3+i); | 
|  | 1155 | while(i--) { | 
|  | 1156 | phba->ModelName[j++] = vpd[index++]; | 
|  | 1157 | if (j == 79) | 
|  | 1158 | break; | 
|  | 1159 | } | 
|  | 1160 | phba->ModelName[j] = 0; | 
|  | 1161 | continue; | 
|  | 1162 | } | 
|  | 1163 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | 
|  | 1164 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | 
|  | 1165 | index += 2; | 
|  | 1166 | i = vpd[index]; | 
|  | 1167 | index += 1; | 
|  | 1168 | j = 0; | 
|  | 1169 | Length -= (3+i); | 
|  | 1170 | while(i--) { | 
|  | 1171 | phba->ProgramType[j++] = vpd[index++]; | 
|  | 1172 | if (j == 255) | 
|  | 1173 | break; | 
|  | 1174 | } | 
|  | 1175 | phba->ProgramType[j] = 0; | 
|  | 1176 | continue; | 
|  | 1177 | } | 
|  | 1178 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | 
|  | 1179 | phba->vpd_flag |= VPD_PORT; | 
|  | 1180 | index += 2; | 
|  | 1181 | i = vpd[index]; | 
|  | 1182 | index += 1; | 
|  | 1183 | j = 0; | 
|  | 1184 | Length -= (3+i); | 
|  | 1185 | while(i--) { | 
|  | 1186 | phba->Port[j++] = vpd[index++]; | 
|  | 1187 | if (j == 19) | 
|  | 1188 | break; | 
|  | 1189 | } | 
|  | 1190 | phba->Port[j] = 0; | 
|  | 1191 | continue; | 
|  | 1192 | } | 
|  | 1193 | else { | 
|  | 1194 | index += 2; | 
|  | 1195 | i = vpd[index]; | 
|  | 1196 | index += 1; | 
|  | 1197 | index += i; | 
|  | 1198 | Length -= (3 + i); | 
|  | 1199 | } | 
|  | 1200 | } | 
|  | 1201 | finished = 0; | 
|  | 1202 | break; | 
|  | 1203 | case 0x78: | 
|  | 1204 | finished = 1; | 
|  | 1205 | break; | 
|  | 1206 | default: | 
|  | 1207 | index ++; | 
|  | 1208 | break; | 
|  | 1209 | } | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1210 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 |  | 
|  | 1212 | return(1); | 
|  | 1213 | } | 
|  | 1214 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1215 | /** | 
|  | 1216 | * lpfc_get_hba_model_desc: Retrieve HBA device model name and description. | 
|  | 1217 | * @phba: pointer to lpfc hba data structure. | 
|  | 1218 | * @mdp: pointer to the data structure to hold the derived model name. | 
|  | 1219 | * @descp: pointer to the data structure to hold the derived description. | 
|  | 1220 | * | 
|  | 1221 | * This routine retrieves HBA's description based on its registered PCI device | 
|  | 1222 | * ID. The @descp passed into this function points to an array of 256 chars. It | 
|  | 1223 | * shall be returned with the model name, maximum speed, and the host bus type. | 
|  | 1224 | * The @mdp passed into this function points to an array of 80 chars. When the | 
|  | 1225 | * function returns, the @mdp will be filled with the model name. | 
|  | 1226 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | static void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | { | 
|  | 1230 | lpfc_vpd_t *vp; | 
| James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1231 | uint16_t dev_id = phba->pcidev->device; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1232 | int max_speed; | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1233 | int GE = 0; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1234 | struct { | 
|  | 1235 | char * name; | 
|  | 1236 | int    max_speed; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1237 | char * bus; | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1238 | } m = {"<Unknown>", 0, ""}; | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1239 |  | 
|  | 1240 | if (mdp && mdp[0] != '\0' | 
|  | 1241 | && descp && descp[0] != '\0') | 
|  | 1242 | return; | 
|  | 1243 |  | 
|  | 1244 | if (phba->lmt & LMT_10Gb) | 
|  | 1245 | max_speed = 10; | 
|  | 1246 | else if (phba->lmt & LMT_8Gb) | 
|  | 1247 | max_speed = 8; | 
|  | 1248 | else if (phba->lmt & LMT_4Gb) | 
|  | 1249 | max_speed = 4; | 
|  | 1250 | else if (phba->lmt & LMT_2Gb) | 
|  | 1251 | max_speed = 2; | 
|  | 1252 | else | 
|  | 1253 | max_speed = 1; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 |  | 
|  | 1255 | vp = &phba->vpd; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 |  | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1257 | switch (dev_id) { | 
| James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1258 | case PCI_DEVICE_ID_FIREFLY: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1259 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; | 
| James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1260 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | case PCI_DEVICE_ID_SUPERFLY: | 
|  | 1262 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1263 | m = (typeof(m)){"LP7000", max_speed,  "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | else | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1265 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | break; | 
|  | 1267 | case PCI_DEVICE_ID_DRAGONFLY: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1268 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | break; | 
|  | 1270 | case PCI_DEVICE_ID_CENTAUR: | 
|  | 1271 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1272 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1273 | else | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1274 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | break; | 
|  | 1276 | case PCI_DEVICE_ID_RFLY: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1277 | m = (typeof(m)){"LP952", max_speed, "PCI"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | break; | 
|  | 1279 | case PCI_DEVICE_ID_PEGASUS: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1280 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | break; | 
|  | 1282 | case PCI_DEVICE_ID_THOR: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1283 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1284 | break; | 
|  | 1285 | case PCI_DEVICE_ID_VIPER: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1286 | m = (typeof(m)){"LPX1000", max_speed,  "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | break; | 
|  | 1288 | case PCI_DEVICE_ID_PFLY: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1289 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1290 | break; | 
|  | 1291 | case PCI_DEVICE_ID_TFLY: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1292 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | break; | 
|  | 1294 | case PCI_DEVICE_ID_HELIOS: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1295 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1296 | break; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1297 | case PCI_DEVICE_ID_HELIOS_SCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1298 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1299 | break; | 
|  | 1300 | case PCI_DEVICE_ID_HELIOS_DCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1301 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1302 | break; | 
|  | 1303 | case PCI_DEVICE_ID_NEPTUNE: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1304 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1305 | break; | 
|  | 1306 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1307 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1308 | break; | 
|  | 1309 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1310 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1311 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1312 | case PCI_DEVICE_ID_BMID: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1313 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | break; | 
|  | 1315 | case PCI_DEVICE_ID_BSMB: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1316 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1317 | break; | 
|  | 1318 | case PCI_DEVICE_ID_ZEPHYR: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1319 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | break; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1321 | case PCI_DEVICE_ID_ZEPHYR_SCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1322 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1323 | break; | 
|  | 1324 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1325 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1326 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1327 | case PCI_DEVICE_ID_ZMID: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1328 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1329 | break; | 
|  | 1330 | case PCI_DEVICE_ID_ZSMB: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1331 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | break; | 
|  | 1333 | case PCI_DEVICE_ID_LP101: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1334 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | break; | 
|  | 1336 | case PCI_DEVICE_ID_LP10000S: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1337 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; | 
| James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1338 | break; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1339 | case PCI_DEVICE_ID_LP11000S: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1340 | m = (typeof(m)){"LP11000-S", max_speed, | 
|  | 1341 | "PCI-X2"}; | 
|  | 1342 | break; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1343 | case PCI_DEVICE_ID_LPE11000S: | 
| James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1344 | m = (typeof(m)){"LPe11000-S", max_speed, | 
|  | 1345 | "PCIe"}; | 
| James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1346 | break; | 
| James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1347 | case PCI_DEVICE_ID_SAT: | 
|  | 1348 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; | 
|  | 1349 | break; | 
|  | 1350 | case PCI_DEVICE_ID_SAT_MID: | 
|  | 1351 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; | 
|  | 1352 | break; | 
|  | 1353 | case PCI_DEVICE_ID_SAT_SMB: | 
|  | 1354 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; | 
|  | 1355 | break; | 
|  | 1356 | case PCI_DEVICE_ID_SAT_DCSP: | 
|  | 1357 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; | 
|  | 1358 | break; | 
|  | 1359 | case PCI_DEVICE_ID_SAT_SCSP: | 
|  | 1360 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; | 
|  | 1361 | break; | 
|  | 1362 | case PCI_DEVICE_ID_SAT_S: | 
|  | 1363 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; | 
|  | 1364 | break; | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1365 | case PCI_DEVICE_ID_HORNET: | 
|  | 1366 | m = (typeof(m)){"LP21000", max_speed, "PCIe"}; | 
|  | 1367 | GE = 1; | 
|  | 1368 | break; | 
|  | 1369 | case PCI_DEVICE_ID_PROTEUS_VF: | 
|  | 1370 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; | 
|  | 1371 | break; | 
|  | 1372 | case PCI_DEVICE_ID_PROTEUS_PF: | 
|  | 1373 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; | 
|  | 1374 | break; | 
|  | 1375 | case PCI_DEVICE_ID_PROTEUS_S: | 
|  | 1376 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; | 
|  | 1377 | break; | 
| James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1378 | default: | 
| Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1379 | m = (typeof(m)){ NULL }; | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1380 | break; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | } | 
| Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1382 |  | 
|  | 1383 | if (mdp && mdp[0] == '\0') | 
|  | 1384 | snprintf(mdp, 79,"%s", m.name); | 
|  | 1385 | if (descp && descp[0] == '\0') | 
|  | 1386 | snprintf(descp, 255, | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1387 | "Emulex %s %d%s %s %s", | 
|  | 1388 | m.name, m.max_speed, | 
|  | 1389 | (GE) ? "GE" : "Gb", | 
|  | 1390 | m.bus, | 
|  | 1391 | (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | } | 
|  | 1393 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1394 | /** | 
|  | 1395 | * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring. | 
|  | 1396 | * @phba: pointer to lpfc hba data structure. | 
|  | 1397 | * @pring: pointer to a IOCB ring. | 
|  | 1398 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | 
|  | 1399 | * | 
|  | 1400 | * This routine posts a given number of IOCBs with the associated DMA buffer | 
|  | 1401 | * descriptors specified by the cnt argument to the given IOCB ring. | 
|  | 1402 | * | 
|  | 1403 | * Return codes | 
|  | 1404 | *   The number of IOCBs NOT able to be posted to the IOCB ring. | 
|  | 1405 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | int | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1407 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | { | 
|  | 1409 | IOCB_t *icmd; | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1410 | struct lpfc_iocbq *iocb; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | struct lpfc_dmabuf *mp1, *mp2; | 
|  | 1412 |  | 
|  | 1413 | cnt += pring->missbufcnt; | 
|  | 1414 |  | 
|  | 1415 | /* While there are buffers to post */ | 
|  | 1416 | while (cnt > 0) { | 
|  | 1417 | /* Allocate buffer for  command iocb */ | 
| James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1418 | iocb = lpfc_sli_get_iocbq(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | if (iocb == NULL) { | 
|  | 1420 | pring->missbufcnt = cnt; | 
|  | 1421 | return cnt; | 
|  | 1422 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | icmd = &iocb->iocb; | 
|  | 1424 |  | 
|  | 1425 | /* 2 buffers can be posted per command */ | 
|  | 1426 | /* Allocate buffer to post */ | 
|  | 1427 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | 
|  | 1428 | if (mp1) | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1429 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); | 
|  | 1430 | if (!mp1 || !mp1->virt) { | 
| Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1431 | kfree(mp1); | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1432 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1433 | pring->missbufcnt = cnt; | 
|  | 1434 | return cnt; | 
|  | 1435 | } | 
|  | 1436 |  | 
|  | 1437 | INIT_LIST_HEAD(&mp1->list); | 
|  | 1438 | /* Allocate buffer to post */ | 
|  | 1439 | if (cnt > 1) { | 
|  | 1440 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | 
|  | 1441 | if (mp2) | 
|  | 1442 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | 
|  | 1443 | &mp2->phys); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1444 | if (!mp2 || !mp2->virt) { | 
| Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1445 | kfree(mp2); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | 
|  | 1447 | kfree(mp1); | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1448 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | pring->missbufcnt = cnt; | 
|  | 1450 | return cnt; | 
|  | 1451 | } | 
|  | 1452 |  | 
|  | 1453 | INIT_LIST_HEAD(&mp2->list); | 
|  | 1454 | } else { | 
|  | 1455 | mp2 = NULL; | 
|  | 1456 | } | 
|  | 1457 |  | 
|  | 1458 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | 
|  | 1459 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | 
|  | 1460 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | 
|  | 1461 | icmd->ulpBdeCount = 1; | 
|  | 1462 | cnt--; | 
|  | 1463 | if (mp2) { | 
|  | 1464 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | 
|  | 1465 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | 
|  | 1466 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | 
|  | 1467 | cnt--; | 
|  | 1468 | icmd->ulpBdeCount = 2; | 
|  | 1469 | } | 
|  | 1470 |  | 
|  | 1471 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | 
|  | 1472 | icmd->ulpLe = 1; | 
|  | 1473 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1474 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { | 
|  | 1475 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | 
|  | 1476 | kfree(mp1); | 
|  | 1477 | cnt++; | 
|  | 1478 | if (mp2) { | 
|  | 1479 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | 
|  | 1480 | kfree(mp2); | 
|  | 1481 | cnt++; | 
|  | 1482 | } | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1483 | lpfc_sli_release_iocbq(phba, iocb); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | pring->missbufcnt = cnt; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | return cnt; | 
|  | 1486 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1488 | if (mp2) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1489 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | } | 
|  | 1491 | pring->missbufcnt = 0; | 
|  | 1492 | return 0; | 
|  | 1493 | } | 
|  | 1494 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1495 | /** | 
|  | 1496 | * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring. | 
|  | 1497 | * @phba: pointer to lpfc hba data structure. | 
|  | 1498 | * | 
|  | 1499 | * This routine posts initial receive IOCB buffers to the ELS ring. The | 
|  | 1500 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | 
|  | 1501 | * set to 64 IOCBs. | 
|  | 1502 | * | 
|  | 1503 | * Return codes | 
|  | 1504 | *   0 - success (currently always success) | 
|  | 1505 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1506 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1507 | lpfc_post_rcv_buf(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | { | 
|  | 1509 | struct lpfc_sli *psli = &phba->sli; | 
|  | 1510 |  | 
|  | 1511 | /* Ring 0, ELS / CT buffers */ | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1512 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | /* Ring 2 - FCP no buffers needed */ | 
|  | 1514 |  | 
|  | 1515 | return 0; | 
|  | 1516 | } | 
|  | 1517 |  | 
|  | 1518 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | 
|  | 1519 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1520 | /** | 
|  | 1521 | * lpfc_sha_init: Set up initial array of hash table entries. | 
|  | 1522 | * @HashResultPointer: pointer to an array as hash table. | 
|  | 1523 | * | 
|  | 1524 | * This routine sets up the initial values to the array of hash table entries | 
|  | 1525 | * for the LC HBAs. | 
|  | 1526 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | static void | 
|  | 1528 | lpfc_sha_init(uint32_t * HashResultPointer) | 
|  | 1529 | { | 
|  | 1530 | HashResultPointer[0] = 0x67452301; | 
|  | 1531 | HashResultPointer[1] = 0xEFCDAB89; | 
|  | 1532 | HashResultPointer[2] = 0x98BADCFE; | 
|  | 1533 | HashResultPointer[3] = 0x10325476; | 
|  | 1534 | HashResultPointer[4] = 0xC3D2E1F0; | 
|  | 1535 | } | 
|  | 1536 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1537 | /** | 
|  | 1538 | * lpfc_sha_iterate: Iterate initial hash table with the working hash table. | 
|  | 1539 | * @HashResultPointer: pointer to an initial/result hash table. | 
|  | 1540 | * @HashWorkingPointer: pointer to an working hash table. | 
|  | 1541 | * | 
|  | 1542 | * This routine iterates an initial hash table pointed by @HashResultPointer | 
|  | 1543 | * with the values from the working hash table pointeed by @HashWorkingPointer. | 
|  | 1544 | * The results are putting back to the initial hash table, returned through | 
|  | 1545 | * the @HashResultPointer as the result hash table. | 
|  | 1546 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | static void | 
|  | 1548 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | 
|  | 1549 | { | 
|  | 1550 | int t; | 
|  | 1551 | uint32_t TEMP; | 
|  | 1552 | uint32_t A, B, C, D, E; | 
|  | 1553 | t = 16; | 
|  | 1554 | do { | 
|  | 1555 | HashWorkingPointer[t] = | 
|  | 1556 | S(1, | 
|  | 1557 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | 
|  | 1558 | 8] ^ | 
|  | 1559 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | 
|  | 1560 | } while (++t <= 79); | 
|  | 1561 | t = 0; | 
|  | 1562 | A = HashResultPointer[0]; | 
|  | 1563 | B = HashResultPointer[1]; | 
|  | 1564 | C = HashResultPointer[2]; | 
|  | 1565 | D = HashResultPointer[3]; | 
|  | 1566 | E = HashResultPointer[4]; | 
|  | 1567 |  | 
|  | 1568 | do { | 
|  | 1569 | if (t < 20) { | 
|  | 1570 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | 
|  | 1571 | } else if (t < 40) { | 
|  | 1572 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | 
|  | 1573 | } else if (t < 60) { | 
|  | 1574 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | 
|  | 1575 | } else { | 
|  | 1576 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | 
|  | 1577 | } | 
|  | 1578 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | 
|  | 1579 | E = D; | 
|  | 1580 | D = C; | 
|  | 1581 | C = S(30, B); | 
|  | 1582 | B = A; | 
|  | 1583 | A = TEMP; | 
|  | 1584 | } while (++t <= 79); | 
|  | 1585 |  | 
|  | 1586 | HashResultPointer[0] += A; | 
|  | 1587 | HashResultPointer[1] += B; | 
|  | 1588 | HashResultPointer[2] += C; | 
|  | 1589 | HashResultPointer[3] += D; | 
|  | 1590 | HashResultPointer[4] += E; | 
|  | 1591 |  | 
|  | 1592 | } | 
|  | 1593 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1594 | /** | 
|  | 1595 | * lpfc_challenge_key: Create challenge key based on WWPN of the HBA. | 
|  | 1596 | * @RandomChallenge: pointer to the entry of host challenge random number array. | 
|  | 1597 | * @HashWorking: pointer to the entry of the working hash array. | 
|  | 1598 | * | 
|  | 1599 | * This routine calculates the working hash array referred by @HashWorking | 
|  | 1600 | * from the challenge random numbers associated with the host, referred by | 
|  | 1601 | * @RandomChallenge. The result is put into the entry of the working hash | 
|  | 1602 | * array and returned by reference through @HashWorking. | 
|  | 1603 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1604 | static void | 
|  | 1605 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | 
|  | 1606 | { | 
|  | 1607 | *HashWorking = (*RandomChallenge ^ *HashWorking); | 
|  | 1608 | } | 
|  | 1609 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1610 | /** | 
|  | 1611 | * lpfc_hba_init: Perform special handling for LC HBA initialization. | 
|  | 1612 | * @phba: pointer to lpfc hba data structure. | 
|  | 1613 | * @hbainit: pointer to an array of unsigned 32-bit integers. | 
|  | 1614 | * | 
|  | 1615 | * This routine performs the special handling for LC HBA initialization. | 
|  | 1616 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1617 | void | 
|  | 1618 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | 
|  | 1619 | { | 
|  | 1620 | int t; | 
|  | 1621 | uint32_t *HashWorking; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1622 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 |  | 
| Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1624 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | if (!HashWorking) | 
|  | 1626 | return; | 
|  | 1627 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | HashWorking[0] = HashWorking[78] = *pwwnn++; | 
|  | 1629 | HashWorking[1] = HashWorking[79] = *pwwnn; | 
|  | 1630 |  | 
|  | 1631 | for (t = 0; t < 7; t++) | 
|  | 1632 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | 
|  | 1633 |  | 
|  | 1634 | lpfc_sha_init(hbainit); | 
|  | 1635 | lpfc_sha_iterate(hbainit, HashWorking); | 
|  | 1636 | kfree(HashWorking); | 
|  | 1637 | } | 
|  | 1638 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1639 | /** | 
|  | 1640 | * lpfc_cleanup: Performs vport cleanups before deleting a vport. | 
|  | 1641 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 1642 | * | 
|  | 1643 | * This routine performs the necessary cleanups before deleting the @vport. | 
|  | 1644 | * It invokes the discovery state machine to perform necessary state | 
|  | 1645 | * transitions and to release the ndlps associated with the @vport. Note, | 
|  | 1646 | * the physical port is treated as @vport 0. | 
|  | 1647 | **/ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1648 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | lpfc_cleanup(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | { | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1651 | struct lpfc_hba   *phba = vport->phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | struct lpfc_nodelist *ndlp, *next_ndlp; | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1653 | int i = 0; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 |  | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1655 | if (phba->link_state > LPFC_LINK_DOWN) | 
|  | 1656 | lpfc_port_link_failure(vport); | 
|  | 1657 |  | 
|  | 1658 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1659 | if (!NLP_CHK_NODE_ACT(ndlp)) { | 
|  | 1660 | ndlp = lpfc_enable_node(vport, ndlp, | 
|  | 1661 | NLP_STE_UNUSED_NODE); | 
|  | 1662 | if (!ndlp) | 
|  | 1663 | continue; | 
|  | 1664 | spin_lock_irq(&phba->ndlp_lock); | 
|  | 1665 | NLP_SET_FREE_REQ(ndlp); | 
|  | 1666 | spin_unlock_irq(&phba->ndlp_lock); | 
|  | 1667 | /* Trigger the release of the ndlp memory */ | 
|  | 1668 | lpfc_nlp_put(ndlp); | 
|  | 1669 | continue; | 
|  | 1670 | } | 
|  | 1671 | spin_lock_irq(&phba->ndlp_lock); | 
|  | 1672 | if (NLP_CHK_FREE_REQ(ndlp)) { | 
|  | 1673 | /* The ndlp should not be in memory free mode already */ | 
|  | 1674 | spin_unlock_irq(&phba->ndlp_lock); | 
|  | 1675 | continue; | 
|  | 1676 | } else | 
|  | 1677 | /* Indicate request for freeing ndlp memory */ | 
|  | 1678 | NLP_SET_FREE_REQ(ndlp); | 
|  | 1679 | spin_unlock_irq(&phba->ndlp_lock); | 
|  | 1680 |  | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1681 | if (vport->port_type != LPFC_PHYSICAL_PORT && | 
|  | 1682 | ndlp->nlp_DID == Fabric_DID) { | 
|  | 1683 | /* Just free up ndlp with Fabric_DID for vports */ | 
|  | 1684 | lpfc_nlp_put(ndlp); | 
|  | 1685 | continue; | 
|  | 1686 | } | 
|  | 1687 |  | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1688 | if (ndlp->nlp_type & NLP_FABRIC) | 
|  | 1689 | lpfc_disc_state_machine(vport, ndlp, NULL, | 
|  | 1690 | NLP_EVT_DEVICE_RECOVERY); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1691 |  | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1692 | lpfc_disc_state_machine(vport, ndlp, NULL, | 
|  | 1693 | NLP_EVT_DEVICE_RM); | 
| James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1694 |  | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1695 | } | 
|  | 1696 |  | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1697 | /* At this point, ALL ndlp's should be gone | 
|  | 1698 | * because of the previous NLP_EVT_DEVICE_RM. | 
|  | 1699 | * Lets wait for this to happen, if needed. | 
|  | 1700 | */ | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1701 | while (!list_empty(&vport->fc_nodes)) { | 
|  | 1702 |  | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1703 | if (i++ > 3000) { | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1704 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1705 | "0233 Nodelist not empty\n"); | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1706 | list_for_each_entry_safe(ndlp, next_ndlp, | 
|  | 1707 | &vport->fc_nodes, nlp_listp) { | 
|  | 1708 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | 
|  | 1709 | LOG_NODE, | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1710 | "0282 did:x%x ndlp:x%p " | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1711 | "usgmap:x%x refcnt:%d\n", | 
|  | 1712 | ndlp->nlp_DID, (void *)ndlp, | 
|  | 1713 | ndlp->nlp_usg_map, | 
|  | 1714 | atomic_read( | 
|  | 1715 | &ndlp->kref.refcount)); | 
|  | 1716 | } | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1717 | break; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1718 | } | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1719 |  | 
|  | 1720 | /* Wait for any activity on ndlps to settle */ | 
|  | 1721 | msleep(10); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1722 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | return; | 
|  | 1724 | } | 
|  | 1725 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1726 | /** | 
|  | 1727 | * lpfc_stop_vport_timers: Stop all the timers associated with a vport. | 
|  | 1728 | * @vport: pointer to a virtual N_Port data structure. | 
|  | 1729 | * | 
|  | 1730 | * This routine stops all the timers associated with a @vport. This function | 
|  | 1731 | * is invoked before disabling or deleting a @vport. Note that the physical | 
|  | 1732 | * port is treated as @vport 0. | 
|  | 1733 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1734 | void | 
|  | 1735 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1736 | { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1737 | del_timer_sync(&vport->els_tmofunc); | 
|  | 1738 | del_timer_sync(&vport->fc_fdmitmo); | 
|  | 1739 | lpfc_can_disctmo(vport); | 
|  | 1740 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | } | 
|  | 1742 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1743 | /** | 
|  | 1744 | * lpfc_stop_phba_timers: Stop all the timers associated with an HBA. | 
|  | 1745 | * @phba: pointer to lpfc hba data structure. | 
|  | 1746 | * | 
|  | 1747 | * This routine stops all the timers associated with a HBA. This function is | 
|  | 1748 | * invoked before either putting a HBA offline or unloading the driver. | 
|  | 1749 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | static void | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1751 | lpfc_stop_phba_timers(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | { | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1753 | del_timer_sync(&phba->fcp_poll_timer); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1754 | lpfc_stop_vport_timers(phba->pport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1755 | del_timer_sync(&phba->sli.mbox_tmo); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1756 | del_timer_sync(&phba->fabric_block_timer); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1757 | phba->hb_outstanding = 0; | 
|  | 1758 | del_timer_sync(&phba->hb_tmofunc); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1759 | del_timer_sync(&phba->eratt_poll); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1760 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1761 | } | 
|  | 1762 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1763 | /** | 
|  | 1764 | * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked. | 
|  | 1765 | * @phba: pointer to lpfc hba data structure. | 
|  | 1766 | * | 
|  | 1767 | * This routine marks a HBA's management interface as blocked. Once the HBA's | 
|  | 1768 | * management interface is marked as blocked, all the user space access to | 
|  | 1769 | * the HBA, whether they are from sysfs interface or libdfc interface will | 
|  | 1770 | * all be blocked. The HBA is set to block the management interface when the | 
|  | 1771 | * driver prepares the HBA interface for online or offline. | 
|  | 1772 | **/ | 
| Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1773 | static void | 
|  | 1774 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | 
|  | 1775 | { | 
|  | 1776 | unsigned long iflag; | 
|  | 1777 |  | 
|  | 1778 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 1779 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | 
|  | 1780 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
|  | 1781 | } | 
|  | 1782 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1783 | /** | 
|  | 1784 | * lpfc_online: Initialize and bring a HBA online. | 
|  | 1785 | * @phba: pointer to lpfc hba data structure. | 
|  | 1786 | * | 
|  | 1787 | * This routine initializes the HBA and brings a HBA online. During this | 
|  | 1788 | * process, the management interface is blocked to prevent user space access | 
|  | 1789 | * to the HBA interfering with the driver initialization. | 
|  | 1790 | * | 
|  | 1791 | * Return codes | 
|  | 1792 | *   0 - successful | 
|  | 1793 | *   1 - failed | 
|  | 1794 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1796 | lpfc_online(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1797 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1798 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1799 | struct lpfc_vport **vports; | 
|  | 1800 | int i; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1801 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | if (!phba) | 
|  | 1803 | return 0; | 
|  | 1804 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1805 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | return 0; | 
|  | 1807 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1808 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1809 | "0458 Bring Adapter online\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1810 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1811 | lpfc_block_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1812 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1813 | if (!lpfc_sli_queue_setup(phba)) { | 
|  | 1814 | lpfc_unblock_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | return 1; | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1816 | } | 
|  | 1817 |  | 
|  | 1818 | if (lpfc_sli_hba_setup(phba)) {	/* Initialize the HBA */ | 
|  | 1819 | lpfc_unblock_mgmt_io(phba); | 
|  | 1820 | return 1; | 
|  | 1821 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1823 | vports = lpfc_create_vport_work_array(phba); | 
|  | 1824 | if (vports != NULL) | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1825 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1826 | struct Scsi_Host *shost; | 
|  | 1827 | shost = lpfc_shost_from_vport(vports[i]); | 
|  | 1828 | spin_lock_irq(shost->host_lock); | 
|  | 1829 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | 
|  | 1830 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | 
|  | 1831 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
|  | 1832 | spin_unlock_irq(shost->host_lock); | 
|  | 1833 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1834 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1836 | lpfc_unblock_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1837 | return 0; | 
|  | 1838 | } | 
|  | 1839 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1840 | /** | 
|  | 1841 | * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked. | 
|  | 1842 | * @phba: pointer to lpfc hba data structure. | 
|  | 1843 | * | 
|  | 1844 | * This routine marks a HBA's management interface as not blocked. Once the | 
|  | 1845 | * HBA's management interface is marked as not blocked, all the user space | 
|  | 1846 | * access to the HBA, whether they are from sysfs interface or libdfc | 
|  | 1847 | * interface will be allowed. The HBA is set to block the management interface | 
|  | 1848 | * when the driver prepares the HBA interface for online or offline and then | 
|  | 1849 | * set to unblock the management interface afterwards. | 
|  | 1850 | **/ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1851 | void | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1852 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | 
|  | 1853 | { | 
|  | 1854 | unsigned long iflag; | 
|  | 1855 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | spin_lock_irqsave(&phba->hbalock, iflag); | 
|  | 1857 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | 
|  | 1858 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1859 | } | 
|  | 1860 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1861 | /** | 
|  | 1862 | * lpfc_offline_prep: Prepare a HBA to be brought offline. | 
|  | 1863 | * @phba: pointer to lpfc hba data structure. | 
|  | 1864 | * | 
|  | 1865 | * This routine is invoked to prepare a HBA to be brought offline. It performs | 
|  | 1866 | * unregistration login to all the nodes on all vports and flushes the mailbox | 
|  | 1867 | * queue to make it ready to be brought offline. | 
|  | 1868 | **/ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1869 | void | 
|  | 1870 | lpfc_offline_prep(struct lpfc_hba * phba) | 
|  | 1871 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1872 | struct lpfc_vport *vport = phba->pport; | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1873 | struct lpfc_nodelist  *ndlp, *next_ndlp; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1874 | struct lpfc_vport **vports; | 
|  | 1875 | int i; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1877 | if (vport->fc_flag & FC_OFFLINE_MODE) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1878 | return; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1880 | lpfc_block_mgmt_io(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 |  | 
|  | 1882 | lpfc_linkdown(phba); | 
|  | 1883 |  | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1884 | /* Issue an unreg_login to all nodes on all vports */ | 
|  | 1885 | vports = lpfc_create_vport_work_array(phba); | 
|  | 1886 | if (vports != NULL) { | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1887 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1888 | struct Scsi_Host *shost; | 
|  | 1889 |  | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1890 | if (vports[i]->load_flag & FC_UNLOADING) | 
|  | 1891 | continue; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1892 | shost =	lpfc_shost_from_vport(vports[i]); | 
|  | 1893 | list_for_each_entry_safe(ndlp, next_ndlp, | 
|  | 1894 | &vports[i]->fc_nodes, | 
|  | 1895 | nlp_listp) { | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1896 | if (!NLP_CHK_NODE_ACT(ndlp)) | 
|  | 1897 | continue; | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1898 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | 
|  | 1899 | continue; | 
|  | 1900 | if (ndlp->nlp_type & NLP_FABRIC) { | 
|  | 1901 | lpfc_disc_state_machine(vports[i], ndlp, | 
|  | 1902 | NULL, NLP_EVT_DEVICE_RECOVERY); | 
|  | 1903 | lpfc_disc_state_machine(vports[i], ndlp, | 
|  | 1904 | NULL, NLP_EVT_DEVICE_RM); | 
|  | 1905 | } | 
|  | 1906 | spin_lock_irq(shost->host_lock); | 
|  | 1907 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | 
|  | 1908 | spin_unlock_irq(shost->host_lock); | 
|  | 1909 | lpfc_unreg_rpi(vports[i], ndlp); | 
|  | 1910 | } | 
|  | 1911 | } | 
|  | 1912 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1913 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 |  | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1915 | lpfc_sli_flush_mbox_queue(phba); | 
|  | 1916 | } | 
|  | 1917 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1918 | /** | 
|  | 1919 | * lpfc_offline: Bring a HBA offline. | 
|  | 1920 | * @phba: pointer to lpfc hba data structure. | 
|  | 1921 | * | 
|  | 1922 | * This routine actually brings a HBA offline. It stops all the timers | 
|  | 1923 | * associated with the HBA, brings down the SLI layer, and eventually | 
|  | 1924 | * marks the HBA as in offline state for the upper layer protocol. | 
|  | 1925 | **/ | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1926 | void | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1927 | lpfc_offline(struct lpfc_hba *phba) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1928 | { | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1929 | struct Scsi_Host  *shost; | 
|  | 1930 | struct lpfc_vport **vports; | 
|  | 1931 | int i; | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1932 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1933 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) | 
| James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1934 | return; | 
| James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1935 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | /* stop all timers associated with this hba */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1937 | lpfc_stop_phba_timers(phba); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1938 | vports = lpfc_create_vport_work_array(phba); | 
|  | 1939 | if (vports != NULL) | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1940 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1941 | lpfc_stop_vport_timers(vports[i]); | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1942 | lpfc_destroy_vport_work_array(phba, vports); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1943 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1944 | "0460 Bring Adapter offline\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1945 | /* Bring down the SLI Layer and cleanup.  The HBA is offline | 
|  | 1946 | now.  */ | 
|  | 1947 | lpfc_sli_hba_down(phba); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1948 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1949 | phba->work_ha = 0; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1951 | vports = lpfc_create_vport_work_array(phba); | 
|  | 1952 | if (vports != NULL) | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1953 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1954 | shost = lpfc_shost_from_vport(vports[i]); | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1955 | spin_lock_irq(shost->host_lock); | 
|  | 1956 | vports[i]->work_port_events = 0; | 
|  | 1957 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | 
|  | 1958 | spin_unlock_irq(shost->host_lock); | 
|  | 1959 | } | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1960 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1961 | } | 
|  | 1962 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1963 | /** | 
|  | 1964 | * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists. | 
|  | 1965 | * @phba: pointer to lpfc hba data structure. | 
|  | 1966 | * | 
|  | 1967 | * This routine is to free all the SCSI buffers and IOCBs from the driver | 
|  | 1968 | * list back to kernel. It is called from lpfc_pci_remove_one to free | 
|  | 1969 | * the internal resources before the device is removed from the system. | 
|  | 1970 | * | 
|  | 1971 | * Return codes | 
|  | 1972 | *   0 - successful (for now, it always returns 0) | 
|  | 1973 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1974 | static int | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | lpfc_scsi_free(struct lpfc_hba *phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1976 | { | 
|  | 1977 | struct lpfc_scsi_buf *sb, *sb_next; | 
|  | 1978 | struct lpfc_iocbq *io, *io_next; | 
|  | 1979 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | /* Release all the lpfc_scsi_bufs maintained by this host. */ | 
|  | 1982 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { | 
|  | 1983 | list_del(&sb->list); | 
|  | 1984 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1985 | sb->dma_handle); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1986 | kfree(sb); | 
|  | 1987 | phba->total_scsi_bufs--; | 
|  | 1988 | } | 
|  | 1989 |  | 
|  | 1990 | /* Release all the lpfc_iocbq entries maintained by this host. */ | 
|  | 1991 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | 
|  | 1992 | list_del(&io->list); | 
|  | 1993 | kfree(io); | 
|  | 1994 | phba->total_iocbq_bufs--; | 
|  | 1995 | } | 
|  | 1996 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1998 |  | 
|  | 1999 | return 0; | 
|  | 2000 | } | 
|  | 2001 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2002 | /** | 
|  | 2003 | * lpfc_create_port: Create an FC port. | 
|  | 2004 | * @phba: pointer to lpfc hba data structure. | 
|  | 2005 | * @instance: a unique integer ID to this FC port. | 
|  | 2006 | * @dev: pointer to the device data structure. | 
|  | 2007 | * | 
|  | 2008 | * This routine creates a FC port for the upper layer protocol. The FC port | 
|  | 2009 | * can be created on top of either a physical port or a virtual port provided | 
|  | 2010 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | 
|  | 2011 | * and associates the FC port created before adding the shost into the SCSI | 
|  | 2012 | * layer. | 
|  | 2013 | * | 
|  | 2014 | * Return codes | 
|  | 2015 | *   @vport - pointer to the virtual N_Port data structure. | 
|  | 2016 | *   NULL - port create failed. | 
|  | 2017 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2018 | struct lpfc_vport * | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2019 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2020 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | struct lpfc_vport *vport; | 
|  | 2022 | struct Scsi_Host  *shost; | 
|  | 2023 | int error = 0; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2024 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2025 | if (dev != &phba->pcidev->dev) | 
|  | 2026 | shost = scsi_host_alloc(&lpfc_vport_template, | 
|  | 2027 | sizeof(struct lpfc_vport)); | 
|  | 2028 | else | 
|  | 2029 | shost = scsi_host_alloc(&lpfc_template, | 
|  | 2030 | sizeof(struct lpfc_vport)); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2031 | if (!shost) | 
|  | 2032 | goto out; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2033 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2034 | vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2035 | vport->phba = phba; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2036 | vport->load_flag |= FC_LOADING; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2037 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | 
| James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2038 | vport->fc_rscn_flush = 0; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2039 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2040 | lpfc_get_vport_cfgparam(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | shost->unique_id = instance; | 
|  | 2042 | shost->max_id = LPFC_MAX_TARGET; | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2043 | shost->max_lun = vport->cfg_max_luns; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2044 | shost->this_id = -1; | 
|  | 2045 | shost->max_cmd_len = 16; | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 2046 |  | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2047 | /* | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | * Set initial can_queue value since 0 is no longer supported and | 
|  | 2049 | * scsi_add_host will fail. This will be adjusted later based on the | 
|  | 2050 | * max xri value determined in hba setup. | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2051 | */ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2053 | if (dev != &phba->pcidev->dev) { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | shost->transportt = lpfc_vport_transport_template; | 
|  | 2055 | vport->port_type = LPFC_NPIV_PORT; | 
|  | 2056 | } else { | 
|  | 2057 | shost->transportt = lpfc_transport_template; | 
|  | 2058 | vport->port_type = LPFC_PHYSICAL_PORT; | 
|  | 2059 | } | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2060 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2061 | /* Initialize all internally managed lists. */ | 
|  | 2062 | INIT_LIST_HEAD(&vport->fc_nodes); | 
|  | 2063 | spin_lock_init(&vport->work_port_lock); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2064 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | init_timer(&vport->fc_disctmo); | 
|  | 2066 | vport->fc_disctmo.function = lpfc_disc_timeout; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2067 | vport->fc_disctmo.data = (unsigned long)vport; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2068 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2069 | init_timer(&vport->fc_fdmitmo); | 
|  | 2070 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2071 | vport->fc_fdmitmo.data = (unsigned long)vport; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2072 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2073 | init_timer(&vport->els_tmofunc); | 
|  | 2074 | vport->els_tmofunc.function = lpfc_els_timeout; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2075 | vport->els_tmofunc.data = (unsigned long)vport; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2076 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2077 | error = scsi_add_host(shost, dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2078 | if (error) | 
|  | 2079 | goto out_put_shost; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2080 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2081 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2082 | list_add_tail(&vport->listentry, &phba->port_list); | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2083 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | return vport; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2085 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2086 | out_put_shost: | 
|  | 2087 | scsi_host_put(shost); | 
|  | 2088 | out: | 
|  | 2089 | return NULL; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2090 | } | 
|  | 2091 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2092 | /** | 
|  | 2093 | * destroy_port: Destroy an FC port. | 
|  | 2094 | * @vport: pointer to an lpfc virtual N_Port data structure. | 
|  | 2095 | * | 
|  | 2096 | * This routine destroys a FC port from the upper layer protocol. All the | 
|  | 2097 | * resources associated with the port are released. | 
|  | 2098 | **/ | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2099 | void | 
|  | 2100 | destroy_port(struct lpfc_vport *vport) | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2101 | { | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2102 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | 
|  | 2103 | struct lpfc_hba  *phba = vport->phba; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2104 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2105 | lpfc_debugfs_terminate(vport); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2106 | fc_remove_host(shost); | 
|  | 2107 | scsi_remove_host(shost); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2108 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2109 | spin_lock_irq(&phba->hbalock); | 
|  | 2110 | list_del_init(&vport->listentry); | 
|  | 2111 | spin_unlock_irq(&phba->hbalock); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2112 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2113 | lpfc_cleanup(vport); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2114 | return; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2115 | } | 
|  | 2116 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2117 | /** | 
|  | 2118 | * lpfc_get_instance: Get a unique integer ID. | 
|  | 2119 | * | 
|  | 2120 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | 
|  | 2121 | * uses the kernel idr facility to perform the task. | 
|  | 2122 | * | 
|  | 2123 | * Return codes: | 
|  | 2124 | *   instance - a unique integer ID allocated as the new instance. | 
|  | 2125 | *   -1 - lpfc get instance failed. | 
|  | 2126 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2127 | int | 
|  | 2128 | lpfc_get_instance(void) | 
|  | 2129 | { | 
|  | 2130 | int instance = 0; | 
|  | 2131 |  | 
|  | 2132 | /* Assign an unused number */ | 
|  | 2133 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | 
|  | 2134 | return -1; | 
|  | 2135 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | 
|  | 2136 | return -1; | 
|  | 2137 | return instance; | 
|  | 2138 | } | 
|  | 2139 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2140 | /** | 
|  | 2141 | * lpfc_scan_finished: method for SCSI layer to detect whether scan is done. | 
|  | 2142 | * @shost: pointer to SCSI host data structure. | 
|  | 2143 | * @time: elapsed time of the scan in jiffies. | 
|  | 2144 | * | 
|  | 2145 | * This routine is called by the SCSI layer with a SCSI host to determine | 
|  | 2146 | * whether the scan host is finished. | 
|  | 2147 | * | 
|  | 2148 | * Note: there is no scan_start function as adapter initialization will have | 
|  | 2149 | * asynchronously kicked off the link initialization. | 
|  | 2150 | * | 
|  | 2151 | * Return codes | 
|  | 2152 | *   0 - SCSI host scan is not over yet. | 
|  | 2153 | *   1 - SCSI host scan is over. | 
|  | 2154 | **/ | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2155 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) | 
|  | 2156 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2157 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2158 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2159 | int stat = 0; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2160 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2161 | spin_lock_irq(shost->host_lock); | 
|  | 2162 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2163 | if (vport->load_flag & FC_UNLOADING) { | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2164 | stat = 1; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2165 | goto finished; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2166 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | if (time >= 30 * HZ) { | 
|  | 2168 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2169 | "0461 Scanning longer than 30 " | 
|  | 2170 | "seconds.  Continuing initialization\n"); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2171 | stat = 1; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2172 | goto finished; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2173 | } | 
|  | 2174 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | 
|  | 2175 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2176 | "0465 Link down longer than 15 " | 
|  | 2177 | "seconds.  Continuing initialization\n"); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2178 | stat = 1; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2179 | goto finished; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2180 | } | 
|  | 2181 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | if (vport->port_state != LPFC_VPORT_READY) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2183 | goto finished; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2184 | if (vport->num_disc_nodes || vport->fc_prli_sent) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2185 | goto finished; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2186 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2187 | goto finished; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2188 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2189 | goto finished; | 
|  | 2190 |  | 
|  | 2191 | stat = 1; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2192 |  | 
|  | 2193 | finished: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2194 | spin_unlock_irq(shost->host_lock); | 
|  | 2195 | return stat; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2196 | } | 
|  | 2197 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2198 | /** | 
|  | 2199 | * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port. | 
|  | 2200 | * @shost: pointer to SCSI host data structure. | 
|  | 2201 | * | 
|  | 2202 | * This routine initializes a given SCSI host attributes on a FC port. The | 
|  | 2203 | * SCSI host can be either on top of a physical port or a virtual port. | 
|  | 2204 | **/ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | void lpfc_host_attrib_init(struct Scsi_Host *shost) | 
|  | 2206 | { | 
|  | 2207 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
|  | 2208 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2209 | /* | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2210 | * Set fixed host attributes.  Must done after lpfc_sli_hba_setup(). | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2211 | */ | 
|  | 2212 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2213 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | 
|  | 2214 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2215 | fc_host_supported_classes(shost) = FC_COS_CLASS3; | 
|  | 2216 |  | 
|  | 2217 | memset(fc_host_supported_fc4s(shost), 0, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2218 | sizeof(fc_host_supported_fc4s(shost))); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2219 | fc_host_supported_fc4s(shost)[2] = 1; | 
|  | 2220 | fc_host_supported_fc4s(shost)[7] = 1; | 
|  | 2221 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2222 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), | 
|  | 2223 | sizeof fc_host_symbolic_name(shost)); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2224 |  | 
|  | 2225 | fc_host_supported_speeds(shost) = 0; | 
|  | 2226 | if (phba->lmt & LMT_10Gb) | 
|  | 2227 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | 
| James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2228 | if (phba->lmt & LMT_8Gb) | 
|  | 2229 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2230 | if (phba->lmt & LMT_4Gb) | 
|  | 2231 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | 
|  | 2232 | if (phba->lmt & LMT_2Gb) | 
|  | 2233 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | 
|  | 2234 | if (phba->lmt & LMT_1Gb) | 
|  | 2235 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | 
|  | 2236 |  | 
|  | 2237 | fc_host_maxframe_size(shost) = | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | | 
|  | 2239 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2240 |  | 
|  | 2241 | /* This value is also unchanging */ | 
|  | 2242 | memset(fc_host_active_fc4s(shost), 0, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2243 | sizeof(fc_host_active_fc4s(shost))); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2244 | fc_host_active_fc4s(shost)[2] = 1; | 
|  | 2245 | fc_host_active_fc4s(shost)[7] = 1; | 
|  | 2246 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2247 | fc_host_max_npiv_vports(shost) = phba->max_vpi; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2248 | spin_lock_irq(shost->host_lock); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2249 | vport->load_flag &= ~FC_LOADING; | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2250 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2251 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2253 | /** | 
|  | 2254 | * lpfc_enable_msix: Enable MSI-X interrupt mode. | 
|  | 2255 | * @phba: pointer to lpfc hba data structure. | 
|  | 2256 | * | 
|  | 2257 | * This routine is invoked to enable the MSI-X interrupt vectors. The kernel | 
|  | 2258 | * function pci_enable_msix() is called to enable the MSI-X vectors. Note that | 
|  | 2259 | * pci_enable_msix(), once invoked, enables either all or nothing, depending | 
|  | 2260 | * on the current availability of PCI vector resources. The device driver is | 
|  | 2261 | * responsible for calling the individual request_irq() to register each MSI-X | 
|  | 2262 | * vector with a interrupt handler, which is done in this function. Note that | 
|  | 2263 | * later when device is unloading, the driver should always call free_irq() | 
|  | 2264 | * on all MSI-X vectors it has done request_irq() on before calling | 
|  | 2265 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | 
|  | 2266 | * will be left with MSI-X enabled and leaks its vectors. | 
|  | 2267 | * | 
|  | 2268 | * Return codes | 
|  | 2269 | *   0 - sucessful | 
|  | 2270 | *   other values - error | 
|  | 2271 | **/ | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2272 | static int | 
|  | 2273 | lpfc_enable_msix(struct lpfc_hba *phba) | 
|  | 2274 | { | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2275 | int rc, i; | 
|  | 2276 | LPFC_MBOXQ_t *pmb; | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2277 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2278 | /* Set up MSI-X multi-message vectors */ | 
|  | 2279 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | 
|  | 2280 | phba->msix_entries[i].entry = i; | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2281 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2282 | /* Configure MSI-X capability structure */ | 
|  | 2283 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2284 | ARRAY_SIZE(phba->msix_entries)); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2285 | if (rc) { | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2286 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2287 | "0420 PCI enable MSI-X failed (%d)\n", rc); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2288 | goto msi_fail_out; | 
|  | 2289 | } else | 
|  | 2290 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | 
|  | 2291 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2292 | "0477 MSI-X entry[%d]: vector=x%x " | 
|  | 2293 | "message=%d\n", i, | 
|  | 2294 | phba->msix_entries[i].vector, | 
|  | 2295 | phba->msix_entries[i].entry); | 
|  | 2296 | /* | 
|  | 2297 | * Assign MSI-X vectors to interrupt handlers | 
|  | 2298 | */ | 
|  | 2299 |  | 
|  | 2300 | /* vector-0 is associated to slow-path handler */ | 
|  | 2301 | rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler, | 
|  | 2302 | IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba); | 
|  | 2303 | if (rc) { | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2304 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2305 | "0421 MSI-X slow-path request_irq failed " | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2306 | "(%d)\n", rc); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2307 | goto msi_fail_out; | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2308 | } | 
|  | 2309 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2310 | /* vector-1 is associated to fast-path handler */ | 
|  | 2311 | rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler, | 
|  | 2312 | IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba); | 
|  | 2313 |  | 
|  | 2314 | if (rc) { | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2315 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2316 | "0429 MSI-X fast-path request_irq failed " | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2317 | "(%d)\n", rc); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2318 | goto irq_fail_out; | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2319 | } | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2320 |  | 
|  | 2321 | /* | 
|  | 2322 | * Configure HBA MSI-X attention conditions to messages | 
|  | 2323 | */ | 
|  | 2324 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 
|  | 2325 |  | 
|  | 2326 | if (!pmb) { | 
|  | 2327 | rc = -ENOMEM; | 
|  | 2328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2329 | "0474 Unable to allocate memory for issuing " | 
|  | 2330 | "MBOX_CONFIG_MSI command\n"); | 
|  | 2331 | goto mem_fail_out; | 
|  | 2332 | } | 
|  | 2333 | rc = lpfc_config_msi(phba, pmb); | 
|  | 2334 | if (rc) | 
|  | 2335 | goto mbx_fail_out; | 
|  | 2336 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | 
|  | 2337 | if (rc != MBX_SUCCESS) { | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2338 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2339 | "0351 Config MSI mailbox command failed, " | 
|  | 2340 | "mbxCmd x%x, mbxStatus x%x\n", | 
|  | 2341 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); | 
|  | 2342 | goto mbx_fail_out; | 
|  | 2343 | } | 
|  | 2344 |  | 
|  | 2345 | /* Free memory allocated for mailbox command */ | 
|  | 2346 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 2347 | return rc; | 
|  | 2348 |  | 
|  | 2349 | mbx_fail_out: | 
|  | 2350 | /* Free memory allocated for mailbox command */ | 
|  | 2351 | mempool_free(pmb, phba->mbox_mem_pool); | 
|  | 2352 |  | 
|  | 2353 | mem_fail_out: | 
|  | 2354 | /* free the irq already requested */ | 
|  | 2355 | free_irq(phba->msix_entries[1].vector, phba); | 
|  | 2356 |  | 
|  | 2357 | irq_fail_out: | 
|  | 2358 | /* free the irq already requested */ | 
|  | 2359 | free_irq(phba->msix_entries[0].vector, phba); | 
|  | 2360 |  | 
|  | 2361 | msi_fail_out: | 
|  | 2362 | /* Unconfigure MSI-X capability structure */ | 
|  | 2363 | pci_disable_msix(phba->pcidev); | 
|  | 2364 | return rc; | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2365 | } | 
|  | 2366 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2367 | /** | 
|  | 2368 | * lpfc_disable_msix: Disable MSI-X interrupt mode. | 
|  | 2369 | * @phba: pointer to lpfc hba data structure. | 
|  | 2370 | * | 
|  | 2371 | * This routine is invoked to release the MSI-X vectors and then disable the | 
|  | 2372 | * MSI-X interrupt mode. | 
|  | 2373 | **/ | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2374 | static void | 
|  | 2375 | lpfc_disable_msix(struct lpfc_hba *phba) | 
|  | 2376 | { | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2377 | int i; | 
|  | 2378 |  | 
|  | 2379 | /* Free up MSI-X multi-message vectors */ | 
|  | 2380 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | 
|  | 2381 | free_irq(phba->msix_entries[i].vector, phba); | 
|  | 2382 | /* Disable MSI-X */ | 
| James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2383 | pci_disable_msix(phba->pcidev); | 
|  | 2384 | } | 
|  | 2385 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2386 | /** | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2387 | * lpfc_enable_msi: Enable MSI interrupt mode. | 
|  | 2388 | * @phba: pointer to lpfc hba data structure. | 
|  | 2389 | * | 
|  | 2390 | * This routine is invoked to enable the MSI interrupt mode. The kernel | 
|  | 2391 | * function pci_enable_msi() is called to enable the MSI vector. The | 
|  | 2392 | * device driver is responsible for calling the request_irq() to register | 
|  | 2393 | * MSI vector with a interrupt the handler, which is done in this function. | 
|  | 2394 | * | 
|  | 2395 | * Return codes | 
|  | 2396 | * 	0 - sucessful | 
|  | 2397 | * 	other values - error | 
|  | 2398 | */ | 
|  | 2399 | static int | 
|  | 2400 | lpfc_enable_msi(struct lpfc_hba *phba) | 
|  | 2401 | { | 
|  | 2402 | int rc; | 
|  | 2403 |  | 
|  | 2404 | rc = pci_enable_msi(phba->pcidev); | 
|  | 2405 | if (!rc) | 
|  | 2406 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2407 | "0462 PCI enable MSI mode success.\n"); | 
|  | 2408 | else { | 
|  | 2409 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2410 | "0471 PCI enable MSI mode failed (%d)\n", rc); | 
|  | 2411 | return rc; | 
|  | 2412 | } | 
|  | 2413 |  | 
|  | 2414 | rc = request_irq(phba->pcidev->irq, lpfc_intr_handler, | 
|  | 2415 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | 
|  | 2416 | if (rc) { | 
|  | 2417 | pci_disable_msi(phba->pcidev); | 
|  | 2418 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 
|  | 2419 | "0478 MSI request_irq failed (%d)\n", rc); | 
|  | 2420 | } | 
|  | 2421 | return rc; | 
|  | 2422 | } | 
|  | 2423 |  | 
|  | 2424 | /** | 
|  | 2425 | * lpfc_disable_msi: Disable MSI interrupt mode. | 
|  | 2426 | * @phba: pointer to lpfc hba data structure. | 
|  | 2427 | * | 
|  | 2428 | * This routine is invoked to disable the MSI interrupt mode. The driver | 
|  | 2429 | * calls free_irq() on MSI vector it has done request_irq() on before | 
|  | 2430 | * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and | 
|  | 2431 | * a device will be left with MSI enabled and leaks its vector. | 
|  | 2432 | */ | 
|  | 2433 |  | 
|  | 2434 | static void | 
|  | 2435 | lpfc_disable_msi(struct lpfc_hba *phba) | 
|  | 2436 | { | 
|  | 2437 | free_irq(phba->pcidev->irq, phba); | 
|  | 2438 | pci_disable_msi(phba->pcidev); | 
|  | 2439 | return; | 
|  | 2440 | } | 
|  | 2441 |  | 
|  | 2442 | /** | 
|  | 2443 | * lpfc_log_intr_mode: Log the active interrupt mode | 
|  | 2444 | * @phba: pointer to lpfc hba data structure. | 
|  | 2445 | * @intr_mode: active interrupt mode adopted. | 
|  | 2446 | * | 
|  | 2447 | * This routine it invoked to log the currently used active interrupt mode | 
|  | 2448 | * to the device. | 
|  | 2449 | */ | 
|  | 2450 | static void | 
|  | 2451 | lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | 
|  | 2452 | { | 
|  | 2453 | switch (intr_mode) { | 
|  | 2454 | case 0: | 
|  | 2455 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2456 | "0470 Enable INTx interrupt mode.\n"); | 
|  | 2457 | break; | 
|  | 2458 | case 1: | 
|  | 2459 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2460 | "0481 Enabled MSI interrupt mode.\n"); | 
|  | 2461 | break; | 
|  | 2462 | case 2: | 
|  | 2463 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2464 | "0480 Enabled MSI-X interrupt mode.\n"); | 
|  | 2465 | break; | 
|  | 2466 | default: | 
|  | 2467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2468 | "0482 Illegal interrupt mode.\n"); | 
|  | 2469 | break; | 
|  | 2470 | } | 
|  | 2471 | return; | 
|  | 2472 | } | 
|  | 2473 |  | 
|  | 2474 | static void | 
|  | 2475 | lpfc_stop_port(struct lpfc_hba *phba) | 
|  | 2476 | { | 
|  | 2477 | /* Clear all interrupt enable conditions */ | 
|  | 2478 | writel(0, phba->HCregaddr); | 
|  | 2479 | readl(phba->HCregaddr); /* flush */ | 
|  | 2480 | /* Clear all pending interrupts */ | 
|  | 2481 | writel(0xffffffff, phba->HAregaddr); | 
|  | 2482 | readl(phba->HAregaddr); /* flush */ | 
|  | 2483 |  | 
|  | 2484 | /* Reset some HBA SLI setup states */ | 
|  | 2485 | lpfc_stop_phba_timers(phba); | 
|  | 2486 | phba->pport->work_port_events = 0; | 
|  | 2487 |  | 
|  | 2488 | return; | 
|  | 2489 | } | 
|  | 2490 |  | 
|  | 2491 | /** | 
|  | 2492 | * lpfc_enable_intr: Enable device interrupt. | 
|  | 2493 | * @phba: pointer to lpfc hba data structure. | 
|  | 2494 | * | 
|  | 2495 | * This routine is invoked to enable device interrupt and associate driver's | 
|  | 2496 | * interrupt handler(s) to interrupt vector(s). Depends on the interrupt | 
|  | 2497 | * mode configured to the driver, the driver will try to fallback from the | 
|  | 2498 | * configured interrupt mode to an interrupt mode which is supported by the | 
|  | 2499 | * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ. | 
|  | 2500 | * | 
|  | 2501 | * Return codes | 
|  | 2502 | *   0 - sucessful | 
|  | 2503 | *   other values - error | 
|  | 2504 | **/ | 
|  | 2505 | static uint32_t | 
|  | 2506 | lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | 
|  | 2507 | { | 
|  | 2508 | uint32_t intr_mode = LPFC_INTR_ERROR; | 
|  | 2509 | int retval; | 
|  | 2510 |  | 
|  | 2511 | if (cfg_mode == 2) { | 
|  | 2512 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | 
|  | 2513 | retval = lpfc_sli_config_port(phba, 3); | 
|  | 2514 | if (!retval) { | 
|  | 2515 | /* Now, try to enable MSI-X interrupt mode */ | 
|  | 2516 | retval = lpfc_enable_msix(phba); | 
|  | 2517 | if (!retval) { | 
|  | 2518 | /* Indicate initialization to MSI-X mode */ | 
|  | 2519 | phba->intr_type = MSIX; | 
|  | 2520 | intr_mode = 2; | 
|  | 2521 | } | 
|  | 2522 | } | 
|  | 2523 | } | 
|  | 2524 |  | 
|  | 2525 | /* Fallback to MSI if MSI-X initialization failed */ | 
|  | 2526 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | 
|  | 2527 | retval = lpfc_enable_msi(phba); | 
|  | 2528 | if (!retval) { | 
|  | 2529 | /* Indicate initialization to MSI mode */ | 
|  | 2530 | phba->intr_type = MSI; | 
|  | 2531 | intr_mode = 1; | 
|  | 2532 | } | 
|  | 2533 | } | 
|  | 2534 |  | 
|  | 2535 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | 
|  | 2536 | if (phba->intr_type == NONE) { | 
|  | 2537 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, | 
|  | 2538 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | 
|  | 2539 | if (!retval) { | 
|  | 2540 | /* Indicate initialization to INTx mode */ | 
|  | 2541 | phba->intr_type = INTx; | 
|  | 2542 | intr_mode = 0; | 
|  | 2543 | } | 
|  | 2544 | } | 
|  | 2545 | return intr_mode; | 
|  | 2546 | } | 
|  | 2547 |  | 
|  | 2548 | /** | 
|  | 2549 | * lpfc_disable_intr: Disable device interrupt. | 
|  | 2550 | * @phba: pointer to lpfc hba data structure. | 
|  | 2551 | * | 
|  | 2552 | * This routine is invoked to disable device interrupt and disassociate the | 
|  | 2553 | * driver's interrupt handler(s) from interrupt vector(s). Depending on the | 
|  | 2554 | * interrupt mode, the driver will release the interrupt vector(s) for the | 
|  | 2555 | * message signaled interrupt. | 
|  | 2556 | **/ | 
|  | 2557 | static void | 
|  | 2558 | lpfc_disable_intr(struct lpfc_hba *phba) | 
|  | 2559 | { | 
|  | 2560 | /* Disable the currently initialized interrupt mode */ | 
|  | 2561 | if (phba->intr_type == MSIX) | 
|  | 2562 | lpfc_disable_msix(phba); | 
|  | 2563 | else if (phba->intr_type == MSI) | 
|  | 2564 | lpfc_disable_msi(phba); | 
|  | 2565 | else if (phba->intr_type == INTx) | 
|  | 2566 | free_irq(phba->pcidev->irq, phba); | 
|  | 2567 |  | 
|  | 2568 | /* Reset interrupt management states */ | 
|  | 2569 | phba->intr_type = NONE; | 
|  | 2570 | phba->sli.slistat.sli_intr = 0; | 
|  | 2571 |  | 
|  | 2572 | return; | 
|  | 2573 | } | 
|  | 2574 |  | 
|  | 2575 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2576 | * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem. | 
|  | 2577 | * @pdev: pointer to PCI device | 
|  | 2578 | * @pid: pointer to PCI device identifier | 
|  | 2579 | * | 
|  | 2580 | * This routine is to be registered to the kernel's PCI subsystem. When an | 
|  | 2581 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at | 
|  | 2582 | * PCI device-specific information of the device and driver to see if the | 
|  | 2583 | * driver state that it can support this kind of device. If the match is | 
|  | 2584 | * successful, the driver core invokes this routine. If this routine | 
|  | 2585 | * determines it can claim the HBA, it does all the initialization that it | 
|  | 2586 | * needs to do to handle the HBA properly. | 
|  | 2587 | * | 
|  | 2588 | * Return code | 
|  | 2589 | *   0 - driver can claim the device | 
|  | 2590 | *   negative value - driver can not claim the device | 
|  | 2591 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | static int __devinit | 
|  | 2593 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | 
|  | 2594 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2595 | struct lpfc_vport *vport = NULL; | 
|  | 2596 | struct lpfc_hba   *phba; | 
|  | 2597 | struct lpfc_sli   *psli; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2599 | struct Scsi_Host  *shost = NULL; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2600 | void *ptr; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | unsigned long bar0map_len, bar2map_len; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2602 | int error = -ENODEV, retval; | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2603 | int  i, hbq_count; | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2604 | uint16_t iotag; | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2605 | uint32_t cfg_mode, intr_mode; | 
| Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2606 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2607 | struct lpfc_adapter_event_header adapter_event; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 |  | 
| Greg Kroah-Hartman | d5f78fb | 2008-02-02 12:13:22 +0100 | [diff] [blame] | 2609 | if (pci_enable_device_mem(pdev)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | goto out; | 
| Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2611 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | goto out_disable_device; | 
|  | 2613 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2614 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); | 
|  | 2615 | if (!phba) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | goto out_release_regions; | 
|  | 2617 |  | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2618 | atomic_set(&phba->fast_event_count, 0); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2619 | spin_lock_init(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 |  | 
| James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2621 | /* Initialize ndlp management spinlock */ | 
|  | 2622 | spin_lock_init(&phba->ndlp_lock); | 
|  | 2623 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | phba->pcidev = pdev; | 
|  | 2625 |  | 
|  | 2626 | /* Assign an unused board number */ | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2627 | if ((phba->brd_no = lpfc_get_instance()) < 0) | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2628 | goto out_free_phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2630 | INIT_LIST_HEAD(&phba->port_list); | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2631 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2632 | /* | 
|  | 2633 | * Get all the module params for configuring this host and then | 
|  | 2634 | * establish the host. | 
|  | 2635 | */ | 
|  | 2636 | lpfc_get_cfgparam(phba); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2637 | phba->max_vpi = LPFC_MAX_VPI; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 |  | 
|  | 2639 | /* Initialize timers used by driver */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2640 | init_timer(&phba->hb_tmofunc); | 
|  | 2641 | phba->hb_tmofunc.function = lpfc_hb_timeout; | 
|  | 2642 | phba->hb_tmofunc.data = (unsigned long)phba; | 
|  | 2643 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | psli = &phba->sli; | 
|  | 2645 | init_timer(&psli->mbox_tmo); | 
|  | 2646 | psli->mbox_tmo.function = lpfc_mbox_timeout; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2647 | psli->mbox_tmo.data = (unsigned long) phba; | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2648 | init_timer(&phba->fcp_poll_timer); | 
|  | 2649 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2650 | phba->fcp_poll_timer.data = (unsigned long) phba; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2651 | init_timer(&phba->fabric_block_timer); | 
|  | 2652 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | 
|  | 2653 | phba->fabric_block_timer.data = (unsigned long) phba; | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2654 | init_timer(&phba->eratt_poll); | 
|  | 2655 | phba->eratt_poll.function = lpfc_poll_eratt; | 
|  | 2656 | phba->eratt_poll.data = (unsigned long) phba; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | pci_set_master(pdev); | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 2659 | pci_save_state(pdev); | 
| Randy Dunlap | 694625c | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 2660 | pci_try_set_mwi(pdev); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 |  | 
|  | 2662 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) | 
|  | 2663 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) | 
|  | 2664 | goto out_idr_remove; | 
|  | 2665 |  | 
|  | 2666 | /* | 
|  | 2667 | * Get the bus address of Bar0 and Bar2 and the number of bytes | 
|  | 2668 | * required by each mapping. | 
|  | 2669 | */ | 
|  | 2670 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); | 
|  | 2671 | bar0map_len        = pci_resource_len(phba->pcidev, 0); | 
|  | 2672 |  | 
|  | 2673 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); | 
|  | 2674 | bar2map_len        = pci_resource_len(phba->pcidev, 2); | 
|  | 2675 |  | 
| Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2676 | /* Map HBA SLIM to a kernel virtual address. */ | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2677 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | 
| Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2678 | if (!phba->slim_memmap_p) { | 
|  | 2679 | error = -ENODEV; | 
|  | 2680 | dev_printk(KERN_ERR, &pdev->dev, | 
|  | 2681 | "ioremap failed for SLIM memory.\n"); | 
|  | 2682 | goto out_idr_remove; | 
|  | 2683 | } | 
|  | 2684 |  | 
|  | 2685 | /* Map HBA Control Registers to a kernel virtual address. */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2686 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | 
| Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2687 | if (!phba->ctrl_regs_memmap_p) { | 
|  | 2688 | error = -ENODEV; | 
|  | 2689 | dev_printk(KERN_ERR, &pdev->dev, | 
|  | 2690 | "ioremap failed for HBA control registers.\n"); | 
|  | 2691 | goto out_iounmap_slim; | 
|  | 2692 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 |  | 
|  | 2694 | /* Allocate memory for SLI-2 structures */ | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2695 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, | 
|  | 2696 | SLI2_SLIM_SIZE, | 
|  | 2697 | &phba->slim2p.phys, | 
|  | 2698 | GFP_KERNEL); | 
|  | 2699 | if (!phba->slim2p.virt) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | goto out_iounmap; | 
|  | 2701 |  | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2702 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2703 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | 
|  | 2704 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); | 
|  | 2705 | phba->IOCBs = (phba->slim2p.virt + | 
|  | 2706 | offsetof(struct lpfc_sli2_slim, IOCBs)); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2708 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, | 
|  | 2709 | lpfc_sli_hbq_size(), | 
|  | 2710 | &phba->hbqslimp.phys, | 
|  | 2711 | GFP_KERNEL); | 
|  | 2712 | if (!phba->hbqslimp.virt) | 
|  | 2713 | goto out_free_slim; | 
|  | 2714 |  | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2715 | hbq_count = lpfc_sli_hbq_count(); | 
|  | 2716 | ptr = phba->hbqslimp.virt; | 
|  | 2717 | for (i = 0; i < hbq_count; ++i) { | 
|  | 2718 | phba->hbqs[i].hbq_virt = ptr; | 
|  | 2719 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | 
|  | 2720 | ptr += (lpfc_hbq_defs[i]->entry_count * | 
|  | 2721 | sizeof(struct lpfc_hbq_entry)); | 
|  | 2722 | } | 
|  | 2723 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | 
|  | 2724 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer  = lpfc_els_hbq_free; | 
|  | 2725 |  | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2726 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | 
|  | 2727 |  | 
| James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2728 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); | 
|  | 2729 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2730 | /* Initialize the SLI Layer to run with lpfc HBAs. */ | 
|  | 2731 | lpfc_sli_setup(phba); | 
|  | 2732 | lpfc_sli_queue_setup(phba); | 
|  | 2733 |  | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2734 | retval = lpfc_mem_alloc(phba); | 
|  | 2735 | if (retval) { | 
|  | 2736 | error = retval; | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2737 | goto out_free_hbqslimp; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2738 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 |  | 
|  | 2740 | /* Initialize and populate the iocb list per host.  */ | 
|  | 2741 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | 
|  | 2742 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { | 
| Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2743 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | if (iocbq_entry == NULL) { | 
|  | 2745 | printk(KERN_ERR "%s: only allocated %d iocbs of " | 
|  | 2746 | "expected %d count. Unloading driver.\n", | 
| Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2747 | __func__, i, LPFC_IOCB_LIST_CNT); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | error = -ENOMEM; | 
|  | 2749 | goto out_free_iocbq; | 
|  | 2750 | } | 
|  | 2751 |  | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2752 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); | 
|  | 2753 | if (iotag == 0) { | 
|  | 2754 | kfree (iocbq_entry); | 
|  | 2755 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | 
|  | 2756 | "Unloading driver.\n", | 
| Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2757 | __func__); | 
| James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2758 | error = -ENOMEM; | 
|  | 2759 | goto out_free_iocbq; | 
|  | 2760 | } | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2761 |  | 
|  | 2762 | spin_lock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); | 
|  | 2764 | phba->total_iocbq_bufs++; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | } | 
|  | 2767 |  | 
|  | 2768 | /* Initialize HBA structure */ | 
|  | 2769 | phba->fc_edtov = FF_DEF_EDTOV; | 
|  | 2770 | phba->fc_ratov = FF_DEF_RATOV; | 
|  | 2771 | phba->fc_altov = FF_DEF_ALTOV; | 
|  | 2772 | phba->fc_arbtov = FF_DEF_ARBTOV; | 
|  | 2773 |  | 
|  | 2774 | INIT_LIST_HEAD(&phba->work_list); | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2775 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | 
|  | 2777 |  | 
| James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2778 | /* Initialize the wait queue head for the kernel thread */ | 
|  | 2779 | init_waitqueue_head(&phba->work_waitq); | 
|  | 2780 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | /* Startup the kernel thread for this host adapter. */ | 
|  | 2782 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | 
|  | 2783 | "lpfc_worker_%d", phba->brd_no); | 
|  | 2784 | if (IS_ERR(phba->worker_thread)) { | 
|  | 2785 | error = PTR_ERR(phba->worker_thread); | 
|  | 2786 | goto out_free_iocbq; | 
|  | 2787 | } | 
|  | 2788 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ | 
| James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2790 | spin_lock_init(&phba->scsi_buf_list_lock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2791 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | 
|  | 2792 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2793 | /* Initialize list of fabric iocbs */ | 
|  | 2794 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | 
|  | 2795 |  | 
| James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2796 | /* Initialize list to save ELS buffers */ | 
|  | 2797 | INIT_LIST_HEAD(&phba->elsbuf); | 
|  | 2798 |  | 
| James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2799 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | if (!vport) | 
|  | 2801 | goto out_kthread_stop; | 
|  | 2802 |  | 
|  | 2803 | shost = lpfc_shost_from_vport(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2804 | phba->pport = vport; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2805 | lpfc_debugfs_initialize(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2806 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2807 | pci_set_drvdata(pdev, shost); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2808 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2809 | phba->MBslimaddr = phba->slim_memmap_p; | 
|  | 2810 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | 
|  | 2811 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | 
|  | 2812 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | 
|  | 2813 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | 
|  | 2814 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2815 | /* Configure sysfs attributes */ | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2816 | if (lpfc_alloc_sysfs_attr(vport)) { | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2817 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2818 | "1476 Failed to allocate sysfs attr\n"); | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2819 | error = -ENOMEM; | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2820 | goto out_destroy_port; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2821 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2823 | cfg_mode = phba->cfg_use_msi; | 
|  | 2824 | while (true) { | 
|  | 2825 | /* Configure and enable interrupt */ | 
|  | 2826 | intr_mode = lpfc_enable_intr(phba, cfg_mode); | 
|  | 2827 | if (intr_mode == LPFC_INTR_ERROR) { | 
|  | 2828 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2829 | "0426 Failed to enable interrupt.\n"); | 
|  | 2830 | goto out_free_sysfs_attr; | 
|  | 2831 | } | 
|  | 2832 | /* HBA SLI setup */ | 
|  | 2833 | if (lpfc_sli_hba_setup(phba)) { | 
|  | 2834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2835 | "1477 Failed to set up hba\n"); | 
|  | 2836 | error = -ENODEV; | 
|  | 2837 | goto out_remove_device; | 
|  | 2838 | } | 
|  | 2839 |  | 
|  | 2840 | /* Wait 50ms for the interrupts of previous mailbox commands */ | 
|  | 2841 | msleep(50); | 
|  | 2842 | /* Check active interrupts received */ | 
|  | 2843 | if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | 
|  | 2844 | /* Log the current active interrupt mode */ | 
|  | 2845 | phba->intr_mode = intr_mode; | 
|  | 2846 | lpfc_log_intr_mode(phba, intr_mode); | 
|  | 2847 | break; | 
|  | 2848 | } else { | 
|  | 2849 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2850 | "0451 Configure interrupt mode (%d) " | 
|  | 2851 | "failed active interrupt test.\n", | 
|  | 2852 | intr_mode); | 
|  | 2853 | if (intr_mode == 0) { | 
|  | 2854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 2855 | "0479 Failed to enable " | 
|  | 2856 | "interrupt.\n"); | 
|  | 2857 | error = -ENODEV; | 
|  | 2858 | goto out_remove_device; | 
|  | 2859 | } | 
|  | 2860 | /* Stop HBA SLI setups */ | 
|  | 2861 | lpfc_stop_port(phba); | 
|  | 2862 | /* Disable the current interrupt mode */ | 
|  | 2863 | lpfc_disable_intr(phba); | 
|  | 2864 | /* Try next level of interrupt mode */ | 
|  | 2865 | cfg_mode = --intr_mode; | 
|  | 2866 | } | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2867 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2868 |  | 
|  | 2869 | /* | 
|  | 2870 | * hba setup may have changed the hba_queue_depth so we need to adjust | 
|  | 2871 | * the value of can_queue. | 
|  | 2872 | */ | 
|  | 2873 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 2874 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { | 
|  | 2875 |  | 
|  | 2876 | if (lpfc_prot_mask && lpfc_prot_guard) { | 
|  | 2877 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2878 | "1478 Registering BlockGuard with the " | 
|  | 2879 | "SCSI layer\n"); | 
|  | 2880 |  | 
|  | 2881 | scsi_host_set_prot(shost, lpfc_prot_mask); | 
|  | 2882 | scsi_host_set_guard(shost, lpfc_prot_guard); | 
|  | 2883 | } | 
|  | 2884 | } | 
|  | 2885 |  | 
|  | 2886 | if (!_dump_buf_data) { | 
|  | 2887 | int pagecnt = 10; | 
|  | 2888 | while (pagecnt) { | 
|  | 2889 | spin_lock_init(&_dump_buf_lock); | 
|  | 2890 | _dump_buf_data = | 
|  | 2891 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | 
|  | 2892 | if (_dump_buf_data) { | 
|  | 2893 | printk(KERN_ERR "BLKGRD allocated %d pages for " | 
|  | 2894 | "_dump_buf_data at 0x%p\n", | 
|  | 2895 | (1 << pagecnt), _dump_buf_data); | 
|  | 2896 | _dump_buf_data_order = pagecnt; | 
|  | 2897 | memset(_dump_buf_data, 0, ((1 << PAGE_SHIFT) | 
|  | 2898 | << pagecnt)); | 
|  | 2899 | break; | 
|  | 2900 | } else { | 
|  | 2901 | --pagecnt; | 
|  | 2902 | } | 
|  | 2903 |  | 
|  | 2904 | } | 
|  | 2905 |  | 
|  | 2906 | if (!_dump_buf_data_order) | 
|  | 2907 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | 
|  | 2908 | "memory for hexdump\n"); | 
|  | 2909 |  | 
|  | 2910 | } else { | 
|  | 2911 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p" | 
|  | 2912 | "\n", _dump_buf_data); | 
|  | 2913 | } | 
|  | 2914 |  | 
|  | 2915 |  | 
|  | 2916 | if (!_dump_buf_dif) { | 
|  | 2917 | int pagecnt = 10; | 
|  | 2918 | while (pagecnt) { | 
|  | 2919 | _dump_buf_dif = | 
|  | 2920 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | 
|  | 2921 | if (_dump_buf_dif) { | 
|  | 2922 | printk(KERN_ERR "BLKGRD allocated %d pages for " | 
|  | 2923 | "_dump_buf_dif at 0x%p\n", | 
|  | 2924 | (1 << pagecnt), _dump_buf_dif); | 
|  | 2925 | _dump_buf_dif_order = pagecnt; | 
|  | 2926 | memset(_dump_buf_dif, 0, ((1 << PAGE_SHIFT) | 
|  | 2927 | << pagecnt)); | 
|  | 2928 | break; | 
|  | 2929 | } else { | 
|  | 2930 | --pagecnt; | 
|  | 2931 | } | 
|  | 2932 |  | 
|  | 2933 | } | 
|  | 2934 |  | 
|  | 2935 | if (!_dump_buf_dif_order) | 
|  | 2936 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | 
|  | 2937 | "memory for hexdump\n"); | 
|  | 2938 |  | 
|  | 2939 | } else { | 
|  | 2940 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n", | 
|  | 2941 | _dump_buf_dif); | 
|  | 2942 | } | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2943 |  | 
|  | 2944 | lpfc_host_attrib_init(shost); | 
|  | 2945 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2946 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | 
|  | 2947 | spin_lock_irq(shost->host_lock); | 
|  | 2948 | lpfc_poll_start_timer(phba); | 
|  | 2949 | spin_unlock_irq(shost->host_lock); | 
|  | 2950 | } | 
| James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2951 |  | 
| James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2952 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 2953 | "0428 Perform SCSI scan\n"); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2954 | /* Send board arrival event to upper layer */ | 
|  | 2955 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | 
|  | 2956 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | 
|  | 2957 | fc_host_post_vendor_event(shost, fc_get_event_number(), | 
|  | 2958 | sizeof(adapter_event), | 
|  | 2959 | (char *) &adapter_event, | 
| James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 2960 | LPFC_NL_VENDOR_ID); | 
| James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2961 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | return 0; | 
|  | 2963 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2964 | out_remove_device: | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2965 | spin_lock_irq(shost->host_lock); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2966 | vport->load_flag |= FC_UNLOADING; | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2967 | spin_unlock_irq(shost->host_lock); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2968 | lpfc_stop_phba_timers(phba); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | phba->pport->work_port_events = 0; | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2970 | lpfc_disable_intr(phba); | 
| James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2971 | lpfc_sli_hba_down(phba); | 
|  | 2972 | lpfc_sli_brdrestart(phba); | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 2973 | out_free_sysfs_attr: | 
|  | 2974 | lpfc_free_sysfs_attr(vport); | 
|  | 2975 | out_destroy_port: | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | destroy_port(vport); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2977 | out_kthread_stop: | 
|  | 2978 | kthread_stop(phba->worker_thread); | 
|  | 2979 | out_free_iocbq: | 
|  | 2980 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | 
|  | 2981 | &phba->lpfc_iocb_list, list) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | kfree(iocbq_entry); | 
|  | 2983 | phba->total_iocbq_bufs--; | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2984 | } | 
|  | 2985 | lpfc_mem_free(phba); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2986 | out_free_hbqslimp: | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2987 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | 
|  | 2988 | phba->hbqslimp.virt, phba->hbqslimp.phys); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | out_free_slim: | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2990 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | 
|  | 2991 | phba->slim2p.virt, phba->slim2p.phys); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2992 | out_iounmap: | 
|  | 2993 | iounmap(phba->ctrl_regs_memmap_p); | 
| Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2994 | out_iounmap_slim: | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | iounmap(phba->slim_memmap_p); | 
|  | 2996 | out_idr_remove: | 
|  | 2997 | idr_remove(&lpfc_hba_index, phba->brd_no); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2998 | out_free_phba: | 
|  | 2999 | kfree(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | out_release_regions: | 
| Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 3001 | pci_release_selected_regions(pdev, bars); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | out_disable_device: | 
|  | 3003 | pci_disable_device(pdev); | 
|  | 3004 | out: | 
| James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 3005 | pci_set_drvdata(pdev, NULL); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3006 | if (shost) | 
|  | 3007 | scsi_host_put(shost); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | return error; | 
|  | 3009 | } | 
|  | 3010 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3011 | /** | 
|  | 3012 | * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem. | 
|  | 3013 | * @pdev: pointer to PCI device | 
|  | 3014 | * | 
|  | 3015 | * This routine is to be registered to the kernel's PCI subsystem. When an | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3016 | * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3017 | * for the HBA device to be removed from the PCI subsystem properly. | 
|  | 3018 | **/ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | static void __devexit | 
|  | 3020 | lpfc_pci_remove_one(struct pci_dev *pdev) | 
|  | 3021 | { | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | struct Scsi_Host  *shost = pci_get_drvdata(pdev); | 
|  | 3023 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3024 | struct lpfc_vport **vports; | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3025 | struct lpfc_hba   *phba = vport->phba; | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3026 | int i; | 
| Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 3027 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | 
|  | 3028 |  | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3029 | spin_lock_irq(&phba->hbalock); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3030 | vport->load_flag |= FC_UNLOADING; | 
| James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3031 | spin_unlock_irq(&phba->hbalock); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3033 | lpfc_free_sysfs_attr(vport); | 
|  | 3034 |  | 
| James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3035 | kthread_stop(phba->worker_thread); | 
|  | 3036 |  | 
| James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 3037 | /* Release all the vports against this physical port */ | 
|  | 3038 | vports = lpfc_create_vport_work_array(phba); | 
|  | 3039 | if (vports != NULL) | 
|  | 3040 | for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++) | 
|  | 3041 | fc_vport_terminate(vports[i]->fc_vport); | 
|  | 3042 | lpfc_destroy_vport_work_array(phba, vports); | 
|  | 3043 |  | 
|  | 3044 | /* Remove FC host and then SCSI host with the physical port */ | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3045 | fc_remove_host(shost); | 
|  | 3046 | scsi_remove_host(shost); | 
| James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3047 | lpfc_cleanup(vport); | 
|  | 3048 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3049 | /* | 
|  | 3050 | * Bring down the SLI Layer. This step disable all interrupts, | 
|  | 3051 | * clears the rings, discards all mailbox commands, and resets | 
|  | 3052 | * the HBA. | 
|  | 3053 | */ | 
|  | 3054 | lpfc_sli_hba_down(phba); | 
|  | 3055 | lpfc_sli_brdrestart(phba); | 
|  | 3056 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3057 | lpfc_stop_phba_timers(phba); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3058 | spin_lock_irq(&phba->hbalock); | 
|  | 3059 | list_del_init(&vport->listentry); | 
|  | 3060 | spin_unlock_irq(&phba->hbalock); | 
|  | 3061 |  | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3062 | lpfc_debugfs_terminate(vport); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3063 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3064 | /* Disable interrupt */ | 
|  | 3065 | lpfc_disable_intr(phba); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3066 |  | 
|  | 3067 | pci_set_drvdata(pdev, NULL); | 
| James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3068 | scsi_host_put(shost); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3069 |  | 
|  | 3070 | /* | 
|  | 3071 | * Call scsi_free before mem_free since scsi bufs are released to their | 
|  | 3072 | * corresponding pools here. | 
|  | 3073 | */ | 
|  | 3074 | lpfc_scsi_free(phba); | 
|  | 3075 | lpfc_mem_free(phba); | 
|  | 3076 |  | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3077 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | 
|  | 3078 | phba->hbqslimp.virt, phba->hbqslimp.phys); | 
| James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3079 |  | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3080 | /* Free resources associated with SLI2 interface */ | 
|  | 3081 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | 
| James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3082 | phba->slim2p.virt, phba->slim2p.phys); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3083 |  | 
|  | 3084 | /* unmap adapter SLIM and Control Registers */ | 
|  | 3085 | iounmap(phba->ctrl_regs_memmap_p); | 
|  | 3086 | iounmap(phba->slim_memmap_p); | 
|  | 3087 |  | 
|  | 3088 | idr_remove(&lpfc_hba_index, phba->brd_no); | 
|  | 3089 |  | 
|  | 3090 | kfree(phba); | 
|  | 3091 |  | 
| Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 3092 | pci_release_selected_regions(pdev, bars); | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3093 | pci_disable_device(pdev); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3094 | } | 
|  | 3095 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3096 | /** | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3097 | * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management. | 
|  | 3098 | * @pdev: pointer to PCI device | 
|  | 3099 | * @msg: power management message | 
|  | 3100 | * | 
|  | 3101 | * This routine is to be registered to the kernel's PCI subsystem to support | 
|  | 3102 | * system Power Management (PM). When PM invokes this method, it quiesces the | 
|  | 3103 | * device by stopping the driver's worker thread for the device, turning off | 
|  | 3104 | * device's interrupt and DMA, and bring the device offline. Note that as the | 
|  | 3105 | * driver implements the minimum PM requirements to a power-aware driver's PM | 
|  | 3106 | * support for suspend/resume -- all the possible PM messages (SUSPEND, | 
|  | 3107 | * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND | 
|  | 3108 | * and the driver will fully reinitialize its device during resume() method | 
|  | 3109 | * call, the driver will set device to PCI_D3hot state in PCI config space | 
|  | 3110 | * instead of setting it according to the @msg provided by the PM. | 
|  | 3111 | * | 
|  | 3112 | * Return code | 
|  | 3113 | *   0 - driver suspended the device | 
|  | 3114 | *   Error otherwise | 
|  | 3115 | **/ | 
|  | 3116 | static int | 
|  | 3117 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | 
|  | 3118 | { | 
|  | 3119 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 
|  | 3120 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
|  | 3121 |  | 
|  | 3122 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 3123 | "0473 PCI device Power Management suspend.\n"); | 
|  | 3124 |  | 
|  | 3125 | /* Bring down the device */ | 
|  | 3126 | lpfc_offline_prep(phba); | 
|  | 3127 | lpfc_offline(phba); | 
|  | 3128 | kthread_stop(phba->worker_thread); | 
|  | 3129 |  | 
|  | 3130 | /* Disable interrupt from device */ | 
|  | 3131 | lpfc_disable_intr(phba); | 
|  | 3132 |  | 
|  | 3133 | /* Save device state to PCI config space */ | 
|  | 3134 | pci_save_state(pdev); | 
|  | 3135 | pci_set_power_state(pdev, PCI_D3hot); | 
|  | 3136 |  | 
|  | 3137 | return 0; | 
|  | 3138 | } | 
|  | 3139 |  | 
|  | 3140 | /** | 
|  | 3141 | * lpfc_pci_resume_one: lpfc PCI func to resume device for power management. | 
|  | 3142 | * @pdev: pointer to PCI device | 
|  | 3143 | * | 
|  | 3144 | * This routine is to be registered to the kernel's PCI subsystem to support | 
|  | 3145 | * system Power Management (PM). When PM invokes this method, it restores | 
|  | 3146 | * the device's PCI config space state and fully reinitializes the device | 
|  | 3147 | * and brings it online. Note that as the driver implements the minimum PM | 
|  | 3148 | * requirements to a power-aware driver's PM for suspend/resume -- all | 
|  | 3149 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | 
|  | 3150 | * method call will be treated as SUSPEND and the driver will fully | 
|  | 3151 | * reinitialize its device during resume() method call, the device will be | 
|  | 3152 | * set to PCI_D0 directly in PCI config space before restoring the state. | 
|  | 3153 | * | 
|  | 3154 | * Return code | 
|  | 3155 | *   0 - driver suspended the device | 
|  | 3156 | *   Error otherwise | 
|  | 3157 | **/ | 
|  | 3158 | static int | 
|  | 3159 | lpfc_pci_resume_one(struct pci_dev *pdev) | 
|  | 3160 | { | 
|  | 3161 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 
|  | 3162 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3163 | uint32_t intr_mode; | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3164 | int error; | 
|  | 3165 |  | 
|  | 3166 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 
|  | 3167 | "0452 PCI device Power Management resume.\n"); | 
|  | 3168 |  | 
|  | 3169 | /* Restore device state from PCI config space */ | 
|  | 3170 | pci_set_power_state(pdev, PCI_D0); | 
|  | 3171 | pci_restore_state(pdev); | 
|  | 3172 | if (pdev->is_busmaster) | 
|  | 3173 | pci_set_master(pdev); | 
|  | 3174 |  | 
|  | 3175 | /* Startup the kernel thread for this host adapter. */ | 
|  | 3176 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | 
|  | 3177 | "lpfc_worker_%d", phba->brd_no); | 
|  | 3178 | if (IS_ERR(phba->worker_thread)) { | 
|  | 3179 | error = PTR_ERR(phba->worker_thread); | 
|  | 3180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 3181 | "0434 PM resume failed to start worker " | 
|  | 3182 | "thread: error=x%x.\n", error); | 
|  | 3183 | return error; | 
|  | 3184 | } | 
|  | 3185 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3186 | /* Configure and enable interrupt */ | 
|  | 3187 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 
|  | 3188 | if (intr_mode == LPFC_INTR_ERROR) { | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3190 | "0430 PM resume Failed to enable interrupt\n"); | 
|  | 3191 | return -EIO; | 
|  | 3192 | } else | 
|  | 3193 | phba->intr_mode = intr_mode; | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3194 |  | 
|  | 3195 | /* Restart HBA and bring it online */ | 
|  | 3196 | lpfc_sli_brdrestart(phba); | 
|  | 3197 | lpfc_online(phba); | 
|  | 3198 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3199 | /* Log the current active interrupt mode */ | 
|  | 3200 | lpfc_log_intr_mode(phba, phba->intr_mode); | 
|  | 3201 |  | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3202 | return 0; | 
|  | 3203 | } | 
|  | 3204 |  | 
|  | 3205 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3206 | * lpfc_io_error_detected: Driver method for handling PCI I/O error detected. | 
|  | 3207 | * @pdev: pointer to PCI device. | 
|  | 3208 | * @state: the current PCI connection state. | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3209 | * | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3210 | * This routine is registered to the PCI subsystem for error handling. This | 
|  | 3211 | * function is called by the PCI subsystem after a PCI bus error affecting | 
|  | 3212 | * this device has been detected. When this function is invoked, it will | 
|  | 3213 | * need to stop all the I/Os and interrupt(s) to the device. Once that is | 
|  | 3214 | * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to | 
|  | 3215 | * perform proper recovery as desired. | 
|  | 3216 | * | 
|  | 3217 | * Return codes | 
|  | 3218 | *   PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | 
|  | 3219 | *   PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 
|  | 3220 | **/ | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3221 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | 
|  | 3222 | pci_channel_state_t state) | 
|  | 3223 | { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3224 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 
|  | 3225 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3226 | struct lpfc_sli *psli = &phba->sli; | 
|  | 3227 | struct lpfc_sli_ring  *pring; | 
|  | 3228 |  | 
| James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3229 | if (state == pci_channel_io_perm_failure) { | 
|  | 3230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 3231 | "0472 PCI channel I/O permanent failure\n"); | 
|  | 3232 | /* Block all SCSI devices' I/Os on the host */ | 
|  | 3233 | lpfc_scsi_dev_block(phba); | 
|  | 3234 | /* Clean up all driver's outstanding SCSI I/Os */ | 
|  | 3235 | lpfc_sli_flush_fcp_rings(phba); | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3236 | return PCI_ERS_RESULT_DISCONNECT; | 
| James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3237 | } | 
| Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 3238 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3239 | pci_disable_device(pdev); | 
|  | 3240 | /* | 
|  | 3241 | * There may be I/Os dropped by the firmware. | 
|  | 3242 | * Error iocb (I/O) on txcmplq and let the SCSI layer | 
|  | 3243 | * retry it after re-establishing link. | 
|  | 3244 | */ | 
|  | 3245 | pring = &psli->ring[psli->fcp_ring]; | 
|  | 3246 | lpfc_sli_abort_iocb_ring(phba, pring); | 
|  | 3247 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3248 | /* Disable interrupt */ | 
|  | 3249 | lpfc_disable_intr(phba); | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3250 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3251 | /* Request a slot reset. */ | 
|  | 3252 | return PCI_ERS_RESULT_NEED_RESET; | 
|  | 3253 | } | 
|  | 3254 |  | 
|  | 3255 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3256 | * lpfc_io_slot_reset: Restart a PCI device from scratch. | 
|  | 3257 | * @pdev: pointer to PCI device. | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3258 | * | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3259 | * This routine is registered to the PCI subsystem for error handling. This is | 
|  | 3260 | * called after PCI bus has been reset to restart the PCI card from scratch, | 
|  | 3261 | * as if from a cold-boot. During the PCI subsystem error recovery, after the | 
|  | 3262 | * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform | 
|  | 3263 | * proper error recovery and then call this routine before calling the .resume | 
|  | 3264 | * method to recover the device. This function will initialize the HBA device, | 
|  | 3265 | * enable the interrupt, but it will just put the HBA to offline state without | 
|  | 3266 | * passing any I/O traffic. | 
|  | 3267 | * | 
|  | 3268 | * Return codes | 
|  | 3269 | *   PCI_ERS_RESULT_RECOVERED - the device has been recovered | 
|  | 3270 | *   PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3271 | */ | 
|  | 3272 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | 
|  | 3273 | { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3274 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 
|  | 3275 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3276 | struct lpfc_sli *psli = &phba->sli; | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3277 | uint32_t intr_mode; | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3278 |  | 
|  | 3279 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 3280 | if (pci_enable_device_mem(pdev)) { | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3281 | printk(KERN_ERR "lpfc: Cannot re-enable " | 
|  | 3282 | "PCI device after reset.\n"); | 
|  | 3283 | return PCI_ERS_RESULT_DISCONNECT; | 
|  | 3284 | } | 
|  | 3285 |  | 
| James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 3286 | pci_restore_state(pdev); | 
|  | 3287 | if (pdev->is_busmaster) | 
|  | 3288 | pci_set_master(pdev); | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3289 |  | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3290 | spin_lock_irq(&phba->hbalock); | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3291 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3292 | spin_unlock_irq(&phba->hbalock); | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3293 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3294 | /* Configure and enable interrupt */ | 
|  | 3295 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 
|  | 3296 | if (intr_mode == LPFC_INTR_ERROR) { | 
|  | 3297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 
|  | 3298 | "0427 Cannot re-enable interrupt after " | 
|  | 3299 | "slot reset.\n"); | 
|  | 3300 | return PCI_ERS_RESULT_DISCONNECT; | 
|  | 3301 | } else | 
|  | 3302 | phba->intr_mode = intr_mode; | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3303 |  | 
|  | 3304 | /* Take device offline; this will perform cleanup */ | 
|  | 3305 | lpfc_offline(phba); | 
|  | 3306 | lpfc_sli_brdrestart(phba); | 
|  | 3307 |  | 
| James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 3308 | /* Log the current active interrupt mode */ | 
|  | 3309 | lpfc_log_intr_mode(phba, phba->intr_mode); | 
|  | 3310 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3311 | return PCI_ERS_RESULT_RECOVERED; | 
|  | 3312 | } | 
|  | 3313 |  | 
|  | 3314 | /** | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3315 | * lpfc_io_resume: Resume PCI I/O operation. | 
|  | 3316 | * @pdev: pointer to PCI device | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3317 | * | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3318 | * This routine is registered to the PCI subsystem for error handling. It is | 
|  | 3319 | * called when kernel error recovery tells the lpfc driver that it is ok to | 
|  | 3320 | * resume normal PCI operation after PCI bus error recovery. After this call, | 
|  | 3321 | * traffic can start to flow from this device again. | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3322 | */ | 
|  | 3323 | static void lpfc_io_resume(struct pci_dev *pdev) | 
|  | 3324 | { | 
| James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3325 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 
|  | 3326 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3327 |  | 
| James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3328 | lpfc_online(phba); | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3329 | } | 
|  | 3330 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | static struct pci_device_id lpfc_id_table[] = { | 
|  | 3332 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | 
|  | 3333 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 3334 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, | 
|  | 3335 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3336 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, | 
|  | 3337 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3338 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | 
|  | 3339 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3340 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | 
|  | 3341 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3342 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | 
|  | 3343 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3344 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | 
|  | 3345 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3346 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | 
|  | 3347 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3348 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | 
|  | 3349 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3350 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, | 
|  | 3351 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3352 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | 
|  | 3353 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3354 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | 
|  | 3355 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, | 
|  | 3357 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3358 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, | 
|  | 3359 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3360 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | 
|  | 3361 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, | 
|  | 3363 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3364 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | 
|  | 3365 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3366 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | 
|  | 3367 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3368 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, | 
|  | 3369 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3370 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, | 
|  | 3371 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3372 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | 
|  | 3373 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, | 
|  | 3375 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3376 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | 
|  | 3377 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3378 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | 
|  | 3379 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3380 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | 
|  | 3381 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3382 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | 
|  | 3383 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3384 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, | 
|  | 3385 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3386 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | 
|  | 3387 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 3388 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, | 
|  | 3389 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3390 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | 
|  | 3391 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3392 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | 
|  | 3393 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3394 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | 
|  | 3395 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3396 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | 
|  | 3397 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3398 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | 
|  | 3399 | PCI_ANY_ID, PCI_ANY_ID, }, | 
| James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3400 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, | 
|  | 3401 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3402 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | 
|  | 3403 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | 3404 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | 
|  | 3405 | PCI_ANY_ID, PCI_ANY_ID, }, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | { 0 } | 
|  | 3407 | }; | 
|  | 3408 |  | 
|  | 3409 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | 
|  | 3410 |  | 
| Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3411 | static struct pci_error_handlers lpfc_err_handler = { | 
|  | 3412 | .error_detected = lpfc_io_error_detected, | 
|  | 3413 | .slot_reset = lpfc_io_slot_reset, | 
|  | 3414 | .resume = lpfc_io_resume, | 
|  | 3415 | }; | 
|  | 3416 |  | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | static struct pci_driver lpfc_driver = { | 
|  | 3418 | .name		= LPFC_DRIVER_NAME, | 
|  | 3419 | .id_table	= lpfc_id_table, | 
|  | 3420 | .probe		= lpfc_pci_probe_one, | 
|  | 3421 | .remove		= __devexit_p(lpfc_pci_remove_one), | 
| James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3422 | .suspend        = lpfc_pci_suspend_one, | 
|  | 3423 | .resume         = lpfc_pci_resume_one, | 
| James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3424 | .err_handler    = &lpfc_err_handler, | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3425 | }; | 
|  | 3426 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3427 | /** | 
|  | 3428 | * lpfc_init: lpfc module initialization routine. | 
|  | 3429 | * | 
|  | 3430 | * This routine is to be invoked when the lpfc module is loaded into the | 
|  | 3431 | * kernel. The special kernel macro module_init() is used to indicate the | 
|  | 3432 | * role of this routine to the kernel as lpfc module entry point. | 
|  | 3433 | * | 
|  | 3434 | * Return codes | 
|  | 3435 | *   0 - successful | 
|  | 3436 | *   -ENOMEM - FC attach transport failed | 
|  | 3437 | *   all others - failed | 
|  | 3438 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3439 | static int __init | 
|  | 3440 | lpfc_init(void) | 
|  | 3441 | { | 
|  | 3442 | int error = 0; | 
|  | 3443 |  | 
|  | 3444 | printk(LPFC_MODULE_DESC "\n"); | 
| James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3445 | printk(LPFC_COPYRIGHT "\n"); | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 |  | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3447 | if (lpfc_enable_npiv) { | 
|  | 3448 | lpfc_transport_functions.vport_create = lpfc_vport_create; | 
|  | 3449 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | 
|  | 3450 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | lpfc_transport_template = | 
|  | 3452 | fc_attach_transport(&lpfc_transport_functions); | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3453 | if (lpfc_transport_template == NULL) | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3454 | return -ENOMEM; | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3455 | if (lpfc_enable_npiv) { | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3456 | lpfc_vport_transport_template = | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3457 | fc_attach_transport(&lpfc_vport_transport_functions); | 
|  | 3458 | if (lpfc_vport_transport_template == NULL) { | 
|  | 3459 | fc_release_transport(lpfc_transport_template); | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3460 | return -ENOMEM; | 
| James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3461 | } | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3462 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | error = pci_register_driver(&lpfc_driver); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3464 | if (error) { | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | fc_release_transport(lpfc_transport_template); | 
| James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3466 | if (lpfc_enable_npiv) | 
|  | 3467 | fc_release_transport(lpfc_vport_transport_template); | 
| James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3468 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 |  | 
|  | 3470 | return error; | 
|  | 3471 | } | 
|  | 3472 |  | 
| James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3473 | /** | 
|  | 3474 | * lpfc_exit: lpfc module removal routine. | 
|  | 3475 | * | 
|  | 3476 | * This routine is invoked when the lpfc module is removed from the kernel. | 
|  | 3477 | * The special kernel macro module_exit() is used to indicate the role of | 
|  | 3478 | * this routine to the kernel as lpfc module exit point. | 
|  | 3479 | */ | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3480 | static void __exit | 
|  | 3481 | lpfc_exit(void) | 
|  | 3482 | { | 
|  | 3483 | pci_unregister_driver(&lpfc_driver); | 
|  | 3484 | fc_release_transport(lpfc_transport_template); | 
| James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3485 | if (lpfc_enable_npiv) | 
|  | 3486 | fc_release_transport(lpfc_vport_transport_template); | 
| James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3487 | if (_dump_buf_data) { | 
|  | 3488 | printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_data " | 
|  | 3489 | "at 0x%p\n", | 
|  | 3490 | (1L << _dump_buf_data_order), _dump_buf_data); | 
|  | 3491 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | 
|  | 3492 | } | 
|  | 3493 |  | 
|  | 3494 | if (_dump_buf_dif) { | 
|  | 3495 | printk(KERN_ERR "BLKGRD freeing %lu pages for _dump_buf_dif " | 
|  | 3496 | "at 0x%p\n", | 
|  | 3497 | (1L << _dump_buf_dif_order), _dump_buf_dif); | 
|  | 3498 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | 
|  | 3499 | } | 
|  | dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | } | 
|  | 3501 |  | 
|  | 3502 | module_init(lpfc_init); | 
|  | 3503 | module_exit(lpfc_exit); | 
|  | 3504 | MODULE_LICENSE("GPL"); | 
|  | 3505 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | 
|  | 3506 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | 
|  | 3507 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |