| 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 | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 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" |
| 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 44 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_version.h" |
| 46 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 47 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 49 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
| 50 | |
| 51 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 52 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | static DEFINE_IDR(lpfc_hba_index); |
| 54 | |
| 55 | /************************************************************************/ |
| 56 | /* */ |
| 57 | /* lpfc_config_port_prep */ |
| 58 | /* This routine will do LPFC initialization prior to the */ |
| 59 | /* CONFIG_PORT mailbox command. This will be initialized */ |
| 60 | /* as a SLI layer callback routine. */ |
| 61 | /* This routine returns 0 on success or -ERESTART if it wants */ |
| 62 | /* the SLI layer to reset the HBA and try again. Any */ |
| 63 | /* other return value indicates an error. */ |
| 64 | /* */ |
| 65 | /************************************************************************/ |
| 66 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 67 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | { |
| 69 | lpfc_vpd_t *vp = &phba->vpd; |
| 70 | int i = 0, rc; |
| 71 | LPFC_MBOXQ_t *pmb; |
| 72 | MAILBOX_t *mb; |
| 73 | char *lpfc_vpd_data = NULL; |
| 74 | uint16_t offset = 0; |
| 75 | static char licensed[56] = |
| 76 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 77 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | |
| 79 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 80 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 81 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | return -ENOMEM; |
| 83 | } |
| 84 | |
| 85 | mb = &pmb->mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 86 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 87 | |
| 88 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 89 | if (init_key) { |
| 90 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 92 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 93 | *ptext = cpu_to_be32(*ptext); |
| 94 | init_key = 0; |
| 95 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 96 | |
| 97 | lpfc_read_nv(phba, pmb); |
| 98 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 99 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 100 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 101 | sizeof (licensed)); |
| 102 | |
| 103 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 104 | |
| 105 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 106 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 107 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 108 | "error, mbxCmd x%x READ_NVPARM, " |
| 109 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | mb->mbxCommand, mb->mbxStatus); |
| 111 | mempool_free(pmb, phba->mbox_mem_pool); |
| 112 | return -ERESTART; |
| 113 | } |
| 114 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 115 | sizeof(phba->wwnn)); |
| 116 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 117 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | } |
| 119 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 120 | phba->sli3_options = 0x0; |
| 121 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | /* Setup and issue mailbox READ REV command */ |
| 123 | lpfc_read_rev(phba, pmb); |
| 124 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 125 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 127 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 129 | mb->mbxCommand, mb->mbxStatus); |
| 130 | mempool_free( pmb, phba->mbox_mem_pool); |
| 131 | return -ERESTART; |
| 132 | } |
| 133 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 134 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 135 | /* |
| 136 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 137 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 138 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 139 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 142 | "0440 Adapter failed to init, READ_REV has " |
| 143 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | mempool_free(pmb, phba->mbox_mem_pool); |
| 145 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | } |
| 147 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 148 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) |
| 149 | return -EINVAL; |
| 150 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 152 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 153 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 154 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 155 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 156 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 157 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 159 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 160 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 161 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 162 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 163 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 164 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 165 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 166 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 167 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 168 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 169 | /* If the sli feature level is less then 9, we must |
| 170 | * tear down all RPIs and VPIs on link down if NPIV |
| 171 | * is enabled. |
| 172 | */ |
| 173 | if (vp->rev.feaLevelHigh < 9) |
| 174 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 177 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 178 | sizeof (phba->RandomData)); |
| 179 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 180 | /* Get adapter VPD information */ |
| 181 | pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL); |
| 182 | if (!pmb->context2) |
| 183 | goto out_free_mbox; |
| 184 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 185 | if (!lpfc_vpd_data) |
| 186 | goto out_free_context2; |
| 187 | |
| 188 | do { |
| 189 | lpfc_dump_mem(phba, pmb, offset); |
| 190 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 191 | |
| 192 | if (rc != MBX_SUCCESS) { |
| 193 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 194 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 197 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 199 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 200 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 202 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 204 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 205 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | |
| 207 | kfree(lpfc_vpd_data); |
| 208 | out_free_context2: |
| 209 | kfree(pmb->context2); |
| 210 | out_free_mbox: |
| 211 | mempool_free(pmb, phba->mbox_mem_pool); |
| 212 | return 0; |
| 213 | } |
| 214 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 215 | /* Completion handler for config async event mailbox command. */ |
| 216 | static void |
| 217 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 218 | { |
| 219 | if (pmboxq->mb.mbxStatus == MBX_SUCCESS) |
| 220 | phba->temp_sensor_support = 1; |
| 221 | else |
| 222 | phba->temp_sensor_support = 0; |
| 223 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 224 | return; |
| 225 | } |
| 226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 227 | /************************************************************************/ |
| 228 | /* */ |
| 229 | /* lpfc_config_port_post */ |
| 230 | /* This routine will do LPFC initialization after the */ |
| 231 | /* CONFIG_PORT mailbox command. This will be initialized */ |
| 232 | /* as a SLI layer callback routine. */ |
| 233 | /* This routine returns 0 on success. Any other return value */ |
| 234 | /* indicates an error. */ |
| 235 | /* */ |
| 236 | /************************************************************************/ |
| 237 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 238 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 240 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | LPFC_MBOXQ_t *pmb; |
| 242 | MAILBOX_t *mb; |
| 243 | struct lpfc_dmabuf *mp; |
| 244 | struct lpfc_sli *psli = &phba->sli; |
| 245 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 246 | int i, j; |
| 247 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | |
| 249 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 250 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 251 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 252 | return -ENOMEM; |
| 253 | } |
| 254 | mb = &pmb->mb; |
| 255 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 256 | /* Get login parameters for NID. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 257 | lpfc_read_sparam(phba, pmb, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 258 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 259 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 260 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 261 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 263 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 264 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 265 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 266 | mempool_free( pmb, phba->mbox_mem_pool); |
| 267 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 268 | kfree(mp); |
| 269 | return -EIO; |
| 270 | } |
| 271 | |
| 272 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 273 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 274 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 276 | kfree(mp); |
| 277 | pmb->context1 = NULL; |
| 278 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 279 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 280 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 281 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 282 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 283 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 284 | vport->fc_sparam.portName.u.wwn); |
| 285 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 286 | sizeof (struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 287 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 288 | sizeof (struct lpfc_name)); |
| 289 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 290 | /* This should be consolidated into parse_vpd ? - mr */ |
| 291 | if (phba->SerialNumber[0] == 0) { |
| 292 | uint8_t *outptr; |
| 293 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 294 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 295 | for (i = 0; i < 12; i++) { |
| 296 | status = *outptr++; |
| 297 | j = ((status & 0xf0) >> 4); |
| 298 | if (j <= 9) |
| 299 | phba->SerialNumber[i] = |
| 300 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 301 | else |
| 302 | phba->SerialNumber[i] = |
| 303 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 304 | i++; |
| 305 | j = (status & 0xf); |
| 306 | if (j <= 9) |
| 307 | phba->SerialNumber[i] = |
| 308 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 309 | else |
| 310 | phba->SerialNumber[i] = |
| 311 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 312 | } |
| 313 | } |
| 314 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 316 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 317 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 319 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 322 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 323 | mempool_free( pmb, phba->mbox_mem_pool); |
| 324 | return -EIO; |
| 325 | } |
| 326 | |
| 327 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 328 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 329 | phba->cfg_hba_queue_depth = |
| 330 | mb->un.varRdConfig.max_xri + 1; |
| 331 | |
| 332 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 333 | |
| 334 | /* Get the default values for Model Name and Description */ |
| 335 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 336 | |
| 337 | if ((phba->cfg_link_speed > LINK_SPEED_10G) |
| 338 | || ((phba->cfg_link_speed == LINK_SPEED_1G) |
| 339 | && !(phba->lmt & LMT_1Gb)) |
| 340 | || ((phba->cfg_link_speed == LINK_SPEED_2G) |
| 341 | && !(phba->lmt & LMT_2Gb)) |
| 342 | || ((phba->cfg_link_speed == LINK_SPEED_4G) |
| 343 | && !(phba->lmt & LMT_4Gb)) |
| 344 | || ((phba->cfg_link_speed == LINK_SPEED_8G) |
| 345 | && !(phba->lmt & LMT_8Gb)) |
| 346 | || ((phba->cfg_link_speed == LINK_SPEED_10G) |
| 347 | && !(phba->lmt & LMT_10Gb))) { |
| 348 | /* Reset link speed to auto */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 349 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 350 | "1302 Invalid speed for this board: " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 351 | "Reset link speed to auto: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 352 | phba->cfg_link_speed); |
| 353 | phba->cfg_link_speed = LINK_SPEED_AUTO; |
| 354 | } |
| 355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 356 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 357 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 358 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 359 | if (psli->ring[psli->extra_ring].cmdringaddr) |
| 360 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 361 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
| 362 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 363 | if (psli->ring[psli->next_ring].cmdringaddr) |
| 364 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 365 | |
| 366 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 367 | if (phba->sli_rev != 3) |
| 368 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 369 | |
| 370 | /* Enable appropriate host interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 371 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 372 | status = readl(phba->HCregaddr); |
| 373 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 374 | if (psli->num_rings > 0) |
| 375 | status |= HC_R0INT_ENA; |
| 376 | if (psli->num_rings > 1) |
| 377 | status |= HC_R1INT_ENA; |
| 378 | if (psli->num_rings > 2) |
| 379 | status |= HC_R2INT_ENA; |
| 380 | if (psli->num_rings > 3) |
| 381 | status |= HC_R3INT_ENA; |
| 382 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 383 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 384 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
| 385 | status &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 386 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 387 | writel(status, phba->HCregaddr); |
| 388 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 389 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * Setup the ring 0 (els) timeout handler |
| 393 | */ |
| 394 | timeout = phba->fc_ratov << 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 395 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 396 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 397 | phba->hb_outstanding = 0; |
| 398 | phba->last_completion_time = jiffies; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 399 | |
| 400 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
| 401 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 402 | pmb->vport = vport; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 403 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 404 | lpfc_set_loopback_flag(phba); |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 405 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 407 | "0454 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | "INIT_LINK, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | mb->mbxCommand, mb->mbxStatus); |
| 410 | |
| 411 | /* Clear all interrupt enable conditions */ |
| 412 | writel(0, phba->HCregaddr); |
| 413 | readl(phba->HCregaddr); /* flush */ |
| 414 | /* Clear all pending interrupts */ |
| 415 | writel(0xffffffff, phba->HAregaddr); |
| 416 | readl(phba->HAregaddr); /* flush */ |
| 417 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 418 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 419 | if (rc != MBX_BUSY) |
| 420 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | return -EIO; |
| 422 | } |
| 423 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 424 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 425 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 426 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 427 | pmb->vport = phba->pport; |
| 428 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 429 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 430 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 431 | lpfc_printf_log(phba, |
| 432 | KERN_ERR, |
| 433 | LOG_INIT, |
| 434 | "0456 Adapter failed to issue " |
| 435 | "ASYNCEVT_ENABLE mbox status x%x \n.", |
| 436 | rc); |
| 437 | mempool_free(pmb, phba->mbox_mem_pool); |
| 438 | } |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 439 | return (0); |
| 440 | } |
| 441 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 442 | /************************************************************************/ |
| 443 | /* */ |
| 444 | /* lpfc_hba_down_prep */ |
| 445 | /* This routine will do LPFC uninitialization before the */ |
| 446 | /* HBA is reset when bringing down the SLI Layer. This will be */ |
| 447 | /* initialized as a SLI layer callback routine. */ |
| 448 | /* This routine returns 0 on success. Any other return value */ |
| 449 | /* indicates an error. */ |
| 450 | /* */ |
| 451 | /************************************************************************/ |
| 452 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 453 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 454 | { |
| 455 | /* Disable interrupts */ |
| 456 | writel(0, phba->HCregaddr); |
| 457 | readl(phba->HCregaddr); /* flush */ |
| 458 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 459 | lpfc_cleanup_discovery_resources(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 460 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /************************************************************************/ |
| 464 | /* */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 465 | /* lpfc_hba_down_post */ |
| 466 | /* This routine will do uninitialization after the HBA is reset */ |
| 467 | /* when bringing down the SLI Layer. */ |
| 468 | /* This routine returns 0 on success. Any other return value */ |
| 469 | /* indicates an error. */ |
| 470 | /* */ |
| 471 | /************************************************************************/ |
| 472 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 473 | lpfc_hba_down_post(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 474 | { |
| 475 | struct lpfc_sli *psli = &phba->sli; |
| 476 | struct lpfc_sli_ring *pring; |
| 477 | struct lpfc_dmabuf *mp, *next_mp; |
| 478 | int i; |
| 479 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 480 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 481 | lpfc_sli_hbqbuf_free_all(phba); |
| 482 | else { |
| 483 | /* Cleanup preposted buffers on the ELS ring */ |
| 484 | pring = &psli->ring[LPFC_ELS_RING]; |
| 485 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 486 | list_del(&mp->list); |
| 487 | pring->postbufq_cnt--; |
| 488 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 489 | kfree(mp); |
| 490 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | for (i = 0; i < psli->num_rings; i++) { |
| 494 | pring = &psli->ring[i]; |
| 495 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 501 | /* HBA heart beat timeout handler */ |
| 502 | void |
| 503 | lpfc_hb_timeout(unsigned long ptr) |
| 504 | { |
| 505 | struct lpfc_hba *phba; |
| 506 | unsigned long iflag; |
| 507 | |
| 508 | phba = (struct lpfc_hba *)ptr; |
| 509 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
| 510 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) |
| 511 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 512 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 513 | |
| 514 | if (phba->work_wait) |
| 515 | wake_up(phba->work_wait); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 521 | { |
| 522 | unsigned long drvr_flag; |
| 523 | |
| 524 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 525 | phba->hb_outstanding = 0; |
| 526 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 527 | |
| 528 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 529 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 530 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 531 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 532 | mod_timer(&phba->hb_tmofunc, |
| 533 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | void |
| 538 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 539 | { |
| 540 | LPFC_MBOXQ_t *pmboxq; |
| 541 | int retval; |
| 542 | struct lpfc_sli *psli = &phba->sli; |
| 543 | |
| 544 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 545 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 546 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 547 | return; |
| 548 | |
| 549 | spin_lock_irq(&phba->pport->work_port_lock); |
| 550 | /* If the timer is already canceled do nothing */ |
| 551 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { |
| 552 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 557 | jiffies)) { |
| 558 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 559 | if (!phba->hb_outstanding) |
| 560 | mod_timer(&phba->hb_tmofunc, |
| 561 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 562 | else |
| 563 | mod_timer(&phba->hb_tmofunc, |
| 564 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 565 | return; |
| 566 | } |
| 567 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 568 | |
| 569 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
| 570 | if (!phba->hb_outstanding) { |
| 571 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 572 | if (!pmboxq) { |
| 573 | mod_timer(&phba->hb_tmofunc, |
| 574 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | lpfc_heart_beat(phba, pmboxq); |
| 579 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 580 | pmboxq->vport = phba->pport; |
| 581 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 582 | |
| 583 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 584 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 585 | mod_timer(&phba->hb_tmofunc, |
| 586 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 587 | return; |
| 588 | } |
| 589 | mod_timer(&phba->hb_tmofunc, |
| 590 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 591 | phba->hb_outstanding = 1; |
| 592 | return; |
| 593 | } else { |
| 594 | /* |
| 595 | * If heart beat timeout called with hb_outstanding set we |
| 596 | * need to take the HBA offline. |
| 597 | */ |
| 598 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 599 | "0459 Adapter heartbeat failure, taking " |
| 600 | "this port offline.\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 601 | |
| 602 | spin_lock_irq(&phba->hbalock); |
| 603 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 604 | spin_unlock_irq(&phba->hbalock); |
| 605 | |
| 606 | lpfc_offline_prep(phba); |
| 607 | lpfc_offline(phba); |
| 608 | lpfc_unblock_mgmt_io(phba); |
| 609 | phba->link_state = LPFC_HBA_ERROR; |
| 610 | lpfc_hba_down_post(phba); |
| 611 | } |
| 612 | } |
| 613 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 614 | /************************************************************************/ |
| 615 | /* */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | /* lpfc_handle_eratt */ |
| 617 | /* This routine will handle processing a Host Attention */ |
| 618 | /* Error Status event. This will be initialized */ |
| 619 | /* as a SLI layer callback routine. */ |
| 620 | /* */ |
| 621 | /************************************************************************/ |
| 622 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 623 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 625 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 626 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 627 | struct lpfc_sli_ring *pring; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 628 | struct lpfc_vport **vports; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 629 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 630 | unsigned long temperature; |
| 631 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 632 | struct Scsi_Host *shost; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 633 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 634 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 635 | /* If the pci channel is offline, ignore possible errors, |
| 636 | * since we cannot communicate with the pci card anyway. */ |
| 637 | if (pci_channel_offline(phba->pcidev)) |
| 638 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 640 | if (phba->work_hs & HS_FFER6 || |
| 641 | phba->work_hs & HS_FFER5) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | /* Re-establishing Link */ |
| 643 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 644 | "1301 Re-establishing Link " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 646 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 647 | phba->work_status[0], phba->work_status[1]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 648 | vports = lpfc_create_vport_work_array(phba); |
| 649 | if (vports != NULL) |
| 650 | for(i = 0; |
| 651 | i < LPFC_MAX_VPORTS && vports[i] != NULL; |
| 652 | i++){ |
| 653 | shost = lpfc_shost_from_vport(vports[i]); |
| 654 | spin_lock_irq(shost->host_lock); |
| 655 | vports[i]->fc_flag |= FC_ESTABLISH_LINK; |
| 656 | spin_unlock_irq(shost->host_lock); |
| 657 | } |
| 658 | lpfc_destroy_vport_work_array(vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 659 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 660 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 661 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 665 | * That could cause the I/Os dropped by the firmware. |
| 666 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 667 | * retry it after re-establishing link. |
| 668 | */ |
| 669 | pring = &psli->ring[psli->fcp_ring]; |
| 670 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 671 | |
| 672 | |
| 673 | /* |
| 674 | * There was a firmware error. Take the hba offline and then |
| 675 | * attempt to restart it. |
| 676 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 677 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 679 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
| 681 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 682 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 683 | return; |
| 684 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 685 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 686 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 687 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 688 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 689 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 690 | temp_event_data.data = (uint32_t)temperature; |
| 691 | |
| 692 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 693 | "0459 Adapter maximum temperature exceeded " |
| 694 | "(%ld), taking this port offline " |
| 695 | "Data: x%x x%x x%x\n", |
| 696 | temperature, phba->work_hs, |
| 697 | phba->work_status[0], phba->work_status[1]); |
| 698 | |
| 699 | shost = lpfc_shost_from_vport(phba->pport); |
| 700 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 701 | sizeof(temp_event_data), |
| 702 | (char *) &temp_event_data, |
| 703 | SCSI_NL_VID_TYPE_PCI |
| 704 | | PCI_VENDOR_ID_EMULEX); |
| 705 | |
| 706 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 707 | lpfc_offline_prep(phba); |
| 708 | lpfc_offline(phba); |
| 709 | lpfc_unblock_mgmt_io(phba); |
| 710 | phba->link_state = LPFC_HBA_ERROR; |
| 711 | lpfc_hba_down_post(phba); |
| 712 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 713 | } else { |
| 714 | /* The if clause above forces this code path when the status |
| 715 | * failure is a value other than FFER6. Do not call the offline |
| 716 | * twice. This is the adapter hardware error path. |
| 717 | */ |
| 718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 719 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 721 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | phba->work_status[0], phba->work_status[1]); |
| 723 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 724 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 726 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 727 | sizeof(event_data), (char *) &event_data, |
| 728 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 729 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 730 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 731 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 732 | spin_unlock_irq(&phba->hbalock); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 733 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | lpfc_offline(phba); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 735 | lpfc_unblock_mgmt_io(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 736 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 737 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | /************************************************************************/ |
| 742 | /* */ |
| 743 | /* lpfc_handle_latt */ |
| 744 | /* This routine will handle processing a Host Attention */ |
| 745 | /* Link Status event. This will be initialized */ |
| 746 | /* as a SLI layer callback routine. */ |
| 747 | /* */ |
| 748 | /************************************************************************/ |
| 749 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 750 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 752 | struct lpfc_vport *vport = phba->pport; |
| 753 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 754 | LPFC_MBOXQ_t *pmb; |
| 755 | volatile uint32_t control; |
| 756 | struct lpfc_dmabuf *mp; |
| 757 | int rc = -ENOMEM; |
| 758 | |
| 759 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 760 | if (!pmb) |
| 761 | goto lpfc_handle_latt_err_exit; |
| 762 | |
| 763 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 764 | if (!mp) |
| 765 | goto lpfc_handle_latt_free_pmb; |
| 766 | |
| 767 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 768 | if (!mp->virt) |
| 769 | goto lpfc_handle_latt_free_mp; |
| 770 | |
| 771 | rc = -EIO; |
| 772 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 773 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 774 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 775 | |
| 776 | psli->slistat.link_event++; |
| 777 | lpfc_read_la(phba, pmb, mp); |
| 778 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 779 | pmb->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 780 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 781 | if (rc == MBX_NOT_FINISHED) |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 782 | goto lpfc_handle_latt_free_mbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 783 | |
| 784 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 785 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 786 | writel(HA_LATT, phba->HAregaddr); |
| 787 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 788 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | |
| 790 | return; |
| 791 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 792 | lpfc_handle_latt_free_mbuf: |
| 793 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 794 | lpfc_handle_latt_free_mp: |
| 795 | kfree(mp); |
| 796 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 797 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 798 | lpfc_handle_latt_err_exit: |
| 799 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 800 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 802 | control = readl(phba->HCregaddr); |
| 803 | control |= HC_LAINT_ENA; |
| 804 | writel(control, phba->HCregaddr); |
| 805 | readl(phba->HCregaddr); /* flush */ |
| 806 | |
| 807 | /* Clear Link Attention in HA REG */ |
| 808 | writel(HA_LATT, phba->HAregaddr); |
| 809 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 810 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 811 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 812 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 813 | |
| 814 | /* The other case is an error from issue_mbox */ |
| 815 | if (rc == -ENOMEM) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 816 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 817 | "0300 READ_LA: no buffers\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 818 | |
| 819 | return; |
| 820 | } |
| 821 | |
| 822 | /************************************************************************/ |
| 823 | /* */ |
| 824 | /* lpfc_parse_vpd */ |
| 825 | /* This routine will parse the VPD data */ |
| 826 | /* */ |
| 827 | /************************************************************************/ |
| 828 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 829 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 830 | { |
| 831 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 832 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 833 | int i, j; |
| 834 | int finished = 0; |
| 835 | int index = 0; |
| 836 | |
| 837 | if (!vpd) |
| 838 | return 0; |
| 839 | |
| 840 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 841 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 842 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 843 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 844 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 845 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | switch (vpd[index]) { |
| 847 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 848 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | index += 1; |
| 850 | lenlo = vpd[index]; |
| 851 | index += 1; |
| 852 | lenhi = vpd[index]; |
| 853 | index += 1; |
| 854 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 855 | index += i; |
| 856 | break; |
| 857 | case 0x90: |
| 858 | index += 1; |
| 859 | lenlo = vpd[index]; |
| 860 | index += 1; |
| 861 | lenhi = vpd[index]; |
| 862 | index += 1; |
| 863 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 864 | if (Length > len - index) |
| 865 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | while (Length > 0) { |
| 867 | /* Look for Serial Number */ |
| 868 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 869 | index += 2; |
| 870 | i = vpd[index]; |
| 871 | index += 1; |
| 872 | j = 0; |
| 873 | Length -= (3+i); |
| 874 | while(i--) { |
| 875 | phba->SerialNumber[j++] = vpd[index++]; |
| 876 | if (j == 31) |
| 877 | break; |
| 878 | } |
| 879 | phba->SerialNumber[j] = 0; |
| 880 | continue; |
| 881 | } |
| 882 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 883 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 884 | index += 2; |
| 885 | i = vpd[index]; |
| 886 | index += 1; |
| 887 | j = 0; |
| 888 | Length -= (3+i); |
| 889 | while(i--) { |
| 890 | phba->ModelDesc[j++] = vpd[index++]; |
| 891 | if (j == 255) |
| 892 | break; |
| 893 | } |
| 894 | phba->ModelDesc[j] = 0; |
| 895 | continue; |
| 896 | } |
| 897 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 898 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 899 | index += 2; |
| 900 | i = vpd[index]; |
| 901 | index += 1; |
| 902 | j = 0; |
| 903 | Length -= (3+i); |
| 904 | while(i--) { |
| 905 | phba->ModelName[j++] = vpd[index++]; |
| 906 | if (j == 79) |
| 907 | break; |
| 908 | } |
| 909 | phba->ModelName[j] = 0; |
| 910 | continue; |
| 911 | } |
| 912 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 913 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 914 | index += 2; |
| 915 | i = vpd[index]; |
| 916 | index += 1; |
| 917 | j = 0; |
| 918 | Length -= (3+i); |
| 919 | while(i--) { |
| 920 | phba->ProgramType[j++] = vpd[index++]; |
| 921 | if (j == 255) |
| 922 | break; |
| 923 | } |
| 924 | phba->ProgramType[j] = 0; |
| 925 | continue; |
| 926 | } |
| 927 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 928 | phba->vpd_flag |= VPD_PORT; |
| 929 | index += 2; |
| 930 | i = vpd[index]; |
| 931 | index += 1; |
| 932 | j = 0; |
| 933 | Length -= (3+i); |
| 934 | while(i--) { |
| 935 | phba->Port[j++] = vpd[index++]; |
| 936 | if (j == 19) |
| 937 | break; |
| 938 | } |
| 939 | phba->Port[j] = 0; |
| 940 | continue; |
| 941 | } |
| 942 | else { |
| 943 | index += 2; |
| 944 | i = vpd[index]; |
| 945 | index += 1; |
| 946 | index += i; |
| 947 | Length -= (3 + i); |
| 948 | } |
| 949 | } |
| 950 | finished = 0; |
| 951 | break; |
| 952 | case 0x78: |
| 953 | finished = 1; |
| 954 | break; |
| 955 | default: |
| 956 | index ++; |
| 957 | break; |
| 958 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 959 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | |
| 961 | return(1); |
| 962 | } |
| 963 | |
| 964 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 965 | 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] | 966 | { |
| 967 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 968 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 969 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 970 | struct { |
| 971 | char * name; |
| 972 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 973 | char * bus; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 974 | } m = {"<Unknown>", 0, ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 975 | |
| 976 | if (mdp && mdp[0] != '\0' |
| 977 | && descp && descp[0] != '\0') |
| 978 | return; |
| 979 | |
| 980 | if (phba->lmt & LMT_10Gb) |
| 981 | max_speed = 10; |
| 982 | else if (phba->lmt & LMT_8Gb) |
| 983 | max_speed = 8; |
| 984 | else if (phba->lmt & LMT_4Gb) |
| 985 | max_speed = 4; |
| 986 | else if (phba->lmt & LMT_2Gb) |
| 987 | max_speed = 2; |
| 988 | else |
| 989 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | |
| 991 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 993 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 994 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 995 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 996 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | case PCI_DEVICE_ID_SUPERFLY: |
| 998 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 999 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1001 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | break; |
| 1003 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1004 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1005 | break; |
| 1006 | case PCI_DEVICE_ID_CENTAUR: |
| 1007 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1008 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1009 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1010 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | break; |
| 1012 | case PCI_DEVICE_ID_RFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1013 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | break; |
| 1015 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1016 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1017 | break; |
| 1018 | case PCI_DEVICE_ID_THOR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1019 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1020 | break; |
| 1021 | case PCI_DEVICE_ID_VIPER: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1022 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | break; |
| 1024 | case PCI_DEVICE_ID_PFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1025 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | break; |
| 1027 | case PCI_DEVICE_ID_TFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1028 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | break; |
| 1030 | case PCI_DEVICE_ID_HELIOS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1031 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1032 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1033 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1034 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1035 | break; |
| 1036 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1037 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1038 | break; |
| 1039 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1040 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1041 | break; |
| 1042 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1043 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1044 | break; |
| 1045 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1046 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1047 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1048 | case PCI_DEVICE_ID_BMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1049 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1050 | break; |
| 1051 | case PCI_DEVICE_ID_BSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1052 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | break; |
| 1054 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1055 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1056 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1057 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1058 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1059 | break; |
| 1060 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1061 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1062 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1063 | case PCI_DEVICE_ID_ZMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1064 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1065 | break; |
| 1066 | case PCI_DEVICE_ID_ZSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1067 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1068 | break; |
| 1069 | case PCI_DEVICE_ID_LP101: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1070 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1071 | break; |
| 1072 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1073 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1074 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1075 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1076 | m = (typeof(m)){"LP11000-S", max_speed, |
| 1077 | "PCI-X2"}; |
| 1078 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1079 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1080 | m = (typeof(m)){"LPe11000-S", max_speed, |
| 1081 | "PCIe"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1082 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1083 | case PCI_DEVICE_ID_SAT: |
| 1084 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; |
| 1085 | break; |
| 1086 | case PCI_DEVICE_ID_SAT_MID: |
| 1087 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; |
| 1088 | break; |
| 1089 | case PCI_DEVICE_ID_SAT_SMB: |
| 1090 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; |
| 1091 | break; |
| 1092 | case PCI_DEVICE_ID_SAT_DCSP: |
| 1093 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; |
| 1094 | break; |
| 1095 | case PCI_DEVICE_ID_SAT_SCSP: |
| 1096 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; |
| 1097 | break; |
| 1098 | case PCI_DEVICE_ID_SAT_S: |
| 1099 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; |
| 1100 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1101 | default: |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1102 | m = (typeof(m)){ NULL }; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1103 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1104 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1105 | |
| 1106 | if (mdp && mdp[0] == '\0') |
| 1107 | snprintf(mdp, 79,"%s", m.name); |
| 1108 | if (descp && descp[0] == '\0') |
| 1109 | snprintf(descp, 255, |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1110 | "Emulex %s %dGb %s Fibre Channel Adapter", |
| 1111 | m.name, m.max_speed, m.bus); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /**************************************************/ |
| 1115 | /* lpfc_post_buffer */ |
| 1116 | /* */ |
| 1117 | /* This routine will post count buffers to the */ |
| 1118 | /* ring with the QUE_RING_BUF_CN command. This */ |
| 1119 | /* allows 3 buffers / command to be posted. */ |
| 1120 | /* Returns the number of buffers NOT posted. */ |
| 1121 | /**************************************************/ |
| 1122 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1123 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1124 | int type) |
| 1125 | { |
| 1126 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1127 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | struct lpfc_dmabuf *mp1, *mp2; |
| 1129 | |
| 1130 | cnt += pring->missbufcnt; |
| 1131 | |
| 1132 | /* While there are buffers to post */ |
| 1133 | while (cnt > 0) { |
| 1134 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1135 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1136 | if (iocb == NULL) { |
| 1137 | pring->missbufcnt = cnt; |
| 1138 | return cnt; |
| 1139 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1140 | icmd = &iocb->iocb; |
| 1141 | |
| 1142 | /* 2 buffers can be posted per command */ |
| 1143 | /* Allocate buffer to post */ |
| 1144 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1145 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1146 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 1147 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1148 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1149 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1150 | pring->missbufcnt = cnt; |
| 1151 | return cnt; |
| 1152 | } |
| 1153 | |
| 1154 | INIT_LIST_HEAD(&mp1->list); |
| 1155 | /* Allocate buffer to post */ |
| 1156 | if (cnt > 1) { |
| 1157 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1158 | if (mp2) |
| 1159 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1160 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1161 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1162 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1163 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1164 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1165 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1166 | pring->missbufcnt = cnt; |
| 1167 | return cnt; |
| 1168 | } |
| 1169 | |
| 1170 | INIT_LIST_HEAD(&mp2->list); |
| 1171 | } else { |
| 1172 | mp2 = NULL; |
| 1173 | } |
| 1174 | |
| 1175 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 1176 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 1177 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 1178 | icmd->ulpBdeCount = 1; |
| 1179 | cnt--; |
| 1180 | if (mp2) { |
| 1181 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 1182 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 1183 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 1184 | cnt--; |
| 1185 | icmd->ulpBdeCount = 2; |
| 1186 | } |
| 1187 | |
| 1188 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 1189 | icmd->ulpLe = 1; |
| 1190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1191 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
| 1192 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1193 | kfree(mp1); |
| 1194 | cnt++; |
| 1195 | if (mp2) { |
| 1196 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 1197 | kfree(mp2); |
| 1198 | cnt++; |
| 1199 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1200 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1202 | return cnt; |
| 1203 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1205 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | } |
| 1208 | pring->missbufcnt = 0; |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
| 1212 | /************************************************************************/ |
| 1213 | /* */ |
| 1214 | /* lpfc_post_rcv_buf */ |
| 1215 | /* This routine post initial rcv buffers to the configured rings */ |
| 1216 | /* */ |
| 1217 | /************************************************************************/ |
| 1218 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1219 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | { |
| 1221 | struct lpfc_sli *psli = &phba->sli; |
| 1222 | |
| 1223 | /* Ring 0, ELS / CT buffers */ |
| 1224 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1); |
| 1225 | /* Ring 2 - FCP no buffers needed */ |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 1231 | |
| 1232 | /************************************************************************/ |
| 1233 | /* */ |
| 1234 | /* lpfc_sha_init */ |
| 1235 | /* */ |
| 1236 | /************************************************************************/ |
| 1237 | static void |
| 1238 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 1239 | { |
| 1240 | HashResultPointer[0] = 0x67452301; |
| 1241 | HashResultPointer[1] = 0xEFCDAB89; |
| 1242 | HashResultPointer[2] = 0x98BADCFE; |
| 1243 | HashResultPointer[3] = 0x10325476; |
| 1244 | HashResultPointer[4] = 0xC3D2E1F0; |
| 1245 | } |
| 1246 | |
| 1247 | /************************************************************************/ |
| 1248 | /* */ |
| 1249 | /* lpfc_sha_iterate */ |
| 1250 | /* */ |
| 1251 | /************************************************************************/ |
| 1252 | static void |
| 1253 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 1254 | { |
| 1255 | int t; |
| 1256 | uint32_t TEMP; |
| 1257 | uint32_t A, B, C, D, E; |
| 1258 | t = 16; |
| 1259 | do { |
| 1260 | HashWorkingPointer[t] = |
| 1261 | S(1, |
| 1262 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 1263 | 8] ^ |
| 1264 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 1265 | } while (++t <= 79); |
| 1266 | t = 0; |
| 1267 | A = HashResultPointer[0]; |
| 1268 | B = HashResultPointer[1]; |
| 1269 | C = HashResultPointer[2]; |
| 1270 | D = HashResultPointer[3]; |
| 1271 | E = HashResultPointer[4]; |
| 1272 | |
| 1273 | do { |
| 1274 | if (t < 20) { |
| 1275 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 1276 | } else if (t < 40) { |
| 1277 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 1278 | } else if (t < 60) { |
| 1279 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 1280 | } else { |
| 1281 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 1282 | } |
| 1283 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 1284 | E = D; |
| 1285 | D = C; |
| 1286 | C = S(30, B); |
| 1287 | B = A; |
| 1288 | A = TEMP; |
| 1289 | } while (++t <= 79); |
| 1290 | |
| 1291 | HashResultPointer[0] += A; |
| 1292 | HashResultPointer[1] += B; |
| 1293 | HashResultPointer[2] += C; |
| 1294 | HashResultPointer[3] += D; |
| 1295 | HashResultPointer[4] += E; |
| 1296 | |
| 1297 | } |
| 1298 | |
| 1299 | /************************************************************************/ |
| 1300 | /* */ |
| 1301 | /* lpfc_challenge_key */ |
| 1302 | /* */ |
| 1303 | /************************************************************************/ |
| 1304 | static void |
| 1305 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 1306 | { |
| 1307 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 1308 | } |
| 1309 | |
| 1310 | /************************************************************************/ |
| 1311 | /* */ |
| 1312 | /* lpfc_hba_init */ |
| 1313 | /* */ |
| 1314 | /************************************************************************/ |
| 1315 | void |
| 1316 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 1317 | { |
| 1318 | int t; |
| 1319 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1320 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1322 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | if (!HashWorking) |
| 1324 | return; |
| 1325 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 1327 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 1328 | |
| 1329 | for (t = 0; t < 7; t++) |
| 1330 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 1331 | |
| 1332 | lpfc_sha_init(hbainit); |
| 1333 | lpfc_sha_iterate(hbainit, HashWorking); |
| 1334 | kfree(HashWorking); |
| 1335 | } |
| 1336 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1337 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1338 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1340 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1342 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1343 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1344 | if (phba->link_state > LPFC_LINK_DOWN) |
| 1345 | lpfc_port_link_failure(vport); |
| 1346 | |
| 1347 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 1348 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1349 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1350 | NLP_EVT_DEVICE_RECOVERY); |
| 1351 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1352 | NLP_EVT_DEVICE_RM); |
| 1353 | } |
| 1354 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1355 | /* At this point, ALL ndlp's should be gone |
| 1356 | * because of the previous NLP_EVT_DEVICE_RM. |
| 1357 | * Lets wait for this to happen, if needed. |
| 1358 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1359 | while (!list_empty(&vport->fc_nodes)) { |
| 1360 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1361 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1362 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1363 | "0233 Nodelist not empty\n"); |
| 1364 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1365 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1366 | |
| 1367 | /* Wait for any activity on ndlps to settle */ |
| 1368 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1369 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | static void |
| 1374 | lpfc_establish_link_tmo(unsigned long ptr) |
| 1375 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1376 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1377 | struct lpfc_vport **vports; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1378 | unsigned long iflag; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1379 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1381 | /* Re-establishing Link, timer expired */ |
| 1382 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1383 | "1300 Re-establishing Link, timer expired " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1384 | "Data: x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1385 | phba->pport->fc_flag, phba->pport->port_state); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1386 | vports = lpfc_create_vport_work_array(phba); |
| 1387 | if (vports != NULL) |
| 1388 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { |
| 1389 | struct Scsi_Host *shost; |
| 1390 | shost = lpfc_shost_from_vport(vports[i]); |
| 1391 | spin_lock_irqsave(shost->host_lock, iflag); |
| 1392 | vports[i]->fc_flag &= ~FC_ESTABLISH_LINK; |
| 1393 | spin_unlock_irqrestore(shost->host_lock, iflag); |
| 1394 | } |
| 1395 | lpfc_destroy_vport_work_array(vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1396 | } |
| 1397 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1398 | void |
| 1399 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1401 | del_timer_sync(&vport->els_tmofunc); |
| 1402 | del_timer_sync(&vport->fc_fdmitmo); |
| 1403 | lpfc_can_disctmo(vport); |
| 1404 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1405 | } |
| 1406 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1408 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1410 | del_timer_sync(&phba->fcp_poll_timer); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | del_timer_sync(&phba->fc_estabtmo); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1412 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1413 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1414 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1415 | phba->hb_outstanding = 0; |
| 1416 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1417 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1421 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1423 | struct lpfc_vport *vport = phba->pport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1424 | struct lpfc_vport **vports; |
| 1425 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1426 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | if (!phba) |
| 1428 | return 0; |
| 1429 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1430 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1431 | return 0; |
| 1432 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1433 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1434 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1435 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1436 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1438 | if (!lpfc_sli_queue_setup(phba)) { |
| 1439 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1440 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
| 1444 | lpfc_unblock_mgmt_io(phba); |
| 1445 | return 1; |
| 1446 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1448 | vports = lpfc_create_vport_work_array(phba); |
| 1449 | if (vports != NULL) |
| 1450 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { |
| 1451 | struct Scsi_Host *shost; |
| 1452 | shost = lpfc_shost_from_vport(vports[i]); |
| 1453 | spin_lock_irq(shost->host_lock); |
| 1454 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 1455 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 1456 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 1457 | spin_unlock_irq(shost->host_lock); |
| 1458 | } |
| 1459 | lpfc_destroy_vport_work_array(vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1461 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | return 0; |
| 1463 | } |
| 1464 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1465 | void |
| 1466 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1471 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
| 1472 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | void |
| 1476 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 1477 | { |
| 1478 | unsigned long iflag; |
| 1479 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1480 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1481 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 1482 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | void |
| 1486 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 1487 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1488 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1489 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1490 | struct lpfc_vport **vports; |
| 1491 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1493 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1494 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1495 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1496 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | |
| 1498 | lpfc_linkdown(phba); |
| 1499 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1500 | /* Issue an unreg_login to all nodes on all vports */ |
| 1501 | vports = lpfc_create_vport_work_array(phba); |
| 1502 | if (vports != NULL) { |
| 1503 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { |
| 1504 | struct Scsi_Host *shost; |
| 1505 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1506 | if (vports[i]->load_flag & FC_UNLOADING) |
| 1507 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1508 | shost = lpfc_shost_from_vport(vports[i]); |
| 1509 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1510 | &vports[i]->fc_nodes, |
| 1511 | nlp_listp) { |
| 1512 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1513 | continue; |
| 1514 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 1515 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1516 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 1517 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1518 | NULL, NLP_EVT_DEVICE_RM); |
| 1519 | } |
| 1520 | spin_lock_irq(shost->host_lock); |
| 1521 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| 1522 | spin_unlock_irq(shost->host_lock); |
| 1523 | lpfc_unreg_rpi(vports[i], ndlp); |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | lpfc_destroy_vport_work_array(vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1529 | lpfc_sli_flush_mbox_queue(phba); |
| 1530 | } |
| 1531 | |
| 1532 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1533 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1534 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1535 | struct Scsi_Host *shost; |
| 1536 | struct lpfc_vport **vports; |
| 1537 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1538 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1539 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1540 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1541 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | /* stop all timers associated with this hba */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1543 | lpfc_stop_phba_timers(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1544 | vports = lpfc_create_vport_work_array(phba); |
| 1545 | if (vports != NULL) |
| 1546 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) |
| 1547 | lpfc_stop_vport_timers(vports[i]); |
| 1548 | lpfc_destroy_vport_work_array(vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1549 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1550 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 1552 | now. */ |
| 1553 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1554 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1555 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1556 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1557 | vports = lpfc_create_vport_work_array(phba); |
| 1558 | if (vports != NULL) |
| 1559 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { |
| 1560 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1561 | spin_lock_irq(shost->host_lock); |
| 1562 | vports[i]->work_port_events = 0; |
| 1563 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 1564 | spin_unlock_irq(shost->host_lock); |
| 1565 | } |
| 1566 | lpfc_destroy_vport_work_array(vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /****************************************************************************** |
| 1570 | * Function name: lpfc_scsi_free |
| 1571 | * |
| 1572 | * Description: Called from lpfc_pci_remove_one free internal driver resources |
| 1573 | * |
| 1574 | ******************************************************************************/ |
| 1575 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1576 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1577 | { |
| 1578 | struct lpfc_scsi_buf *sb, *sb_next; |
| 1579 | struct lpfc_iocbq *io, *io_next; |
| 1580 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1581 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
| 1583 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 1584 | list_del(&sb->list); |
| 1585 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1586 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | kfree(sb); |
| 1588 | phba->total_scsi_bufs--; |
| 1589 | } |
| 1590 | |
| 1591 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 1592 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 1593 | list_del(&io->list); |
| 1594 | kfree(io); |
| 1595 | phba->total_iocbq_bufs--; |
| 1596 | } |
| 1597 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1598 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1599 | |
| 1600 | return 0; |
| 1601 | } |
| 1602 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1603 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1604 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1605 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1606 | struct lpfc_vport *vport; |
| 1607 | struct Scsi_Host *shost; |
| 1608 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1609 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1610 | if (dev != &phba->pcidev->dev) |
| 1611 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 1612 | sizeof(struct lpfc_vport)); |
| 1613 | else |
| 1614 | shost = scsi_host_alloc(&lpfc_template, |
| 1615 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1616 | if (!shost) |
| 1617 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | vport = (struct lpfc_vport *) shost->hostdata; |
| 1620 | vport->phba = phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1621 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1622 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1623 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1624 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1625 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1626 | shost->unique_id = instance; |
| 1627 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1628 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1629 | shost->this_id = -1; |
| 1630 | shost->max_cmd_len = 16; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1631 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1632 | * Set initial can_queue value since 0 is no longer supported and |
| 1633 | * scsi_add_host will fail. This will be adjusted later based on the |
| 1634 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1635 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1636 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1637 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1638 | shost->transportt = lpfc_vport_transport_template; |
| 1639 | vport->port_type = LPFC_NPIV_PORT; |
| 1640 | } else { |
| 1641 | shost->transportt = lpfc_transport_template; |
| 1642 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 1643 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1644 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | /* Initialize all internally managed lists. */ |
| 1646 | INIT_LIST_HEAD(&vport->fc_nodes); |
| 1647 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | init_timer(&vport->fc_disctmo); |
| 1650 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1651 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1652 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1653 | init_timer(&vport->fc_fdmitmo); |
| 1654 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1655 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1656 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | init_timer(&vport->els_tmofunc); |
| 1658 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1659 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1660 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1661 | error = scsi_add_host(shost, dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1662 | if (error) |
| 1663 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1664 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1665 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1666 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1667 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1668 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1669 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1670 | out_put_shost: |
| 1671 | scsi_host_put(shost); |
| 1672 | out: |
| 1673 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1676 | void |
| 1677 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1678 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1679 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1680 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1681 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1682 | kfree(vport->vname); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1683 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1684 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1685 | fc_remove_host(shost); |
| 1686 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1687 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1688 | spin_lock_irq(&phba->hbalock); |
| 1689 | list_del_init(&vport->listentry); |
| 1690 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1691 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1692 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1693 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1696 | int |
| 1697 | lpfc_get_instance(void) |
| 1698 | { |
| 1699 | int instance = 0; |
| 1700 | |
| 1701 | /* Assign an unused number */ |
| 1702 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 1703 | return -1; |
| 1704 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 1705 | return -1; |
| 1706 | return instance; |
| 1707 | } |
| 1708 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1709 | /* |
| 1710 | * Note: there is no scan_start function as adapter initialization |
| 1711 | * will have asynchronously kicked off the link initialization. |
| 1712 | */ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1713 | |
| 1714 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 1715 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1716 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1717 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1718 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1719 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1720 | spin_lock_irq(shost->host_lock); |
| 1721 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1722 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1723 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1724 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1725 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1726 | if (time >= 30 * HZ) { |
| 1727 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1728 | "0461 Scanning longer than 30 " |
| 1729 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1730 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1731 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | } |
| 1733 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 1734 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1735 | "0465 Link down longer than 15 " |
| 1736 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1737 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1742 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1744 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1746 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1748 | goto finished; |
| 1749 | |
| 1750 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1751 | |
| 1752 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1753 | spin_unlock_irq(shost->host_lock); |
| 1754 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 1758 | { |
| 1759 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1760 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1761 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1762 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1763 | */ |
| 1764 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1765 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 1766 | 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] | 1767 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 1768 | |
| 1769 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1770 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1771 | fc_host_supported_fc4s(shost)[2] = 1; |
| 1772 | fc_host_supported_fc4s(shost)[7] = 1; |
| 1773 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1774 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 1775 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1776 | |
| 1777 | fc_host_supported_speeds(shost) = 0; |
| 1778 | if (phba->lmt & LMT_10Gb) |
| 1779 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1780 | if (phba->lmt & LMT_8Gb) |
| 1781 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1782 | if (phba->lmt & LMT_4Gb) |
| 1783 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 1784 | if (phba->lmt & LMT_2Gb) |
| 1785 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 1786 | if (phba->lmt & LMT_1Gb) |
| 1787 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 1788 | |
| 1789 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1790 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 1791 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1792 | |
| 1793 | /* This value is also unchanging */ |
| 1794 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1796 | fc_host_active_fc4s(shost)[2] = 1; |
| 1797 | fc_host_active_fc4s(shost)[7] = 1; |
| 1798 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1799 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1800 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1801 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1802 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1803 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1804 | |
| 1805 | static int __devinit |
| 1806 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 1807 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1808 | struct lpfc_vport *vport = NULL; |
| 1809 | struct lpfc_hba *phba; |
| 1810 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1812 | struct Scsi_Host *shost = NULL; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1813 | void *ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | unsigned long bar0map_len, bar2map_len; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1815 | int error = -ENODEV, retval; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1816 | int i, hbq_count; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1817 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | |
| 1819 | if (pci_enable_device(pdev)) |
| 1820 | goto out; |
| 1821 | if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) |
| 1822 | goto out_disable_device; |
| 1823 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1824 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
| 1825 | if (!phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | goto out_release_regions; |
| 1827 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1828 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | phba->pcidev = pdev; |
| 1831 | |
| 1832 | /* Assign an unused board number */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1833 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1834 | goto out_free_phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1837 | /* |
| 1838 | * Get all the module params for configuring this host and then |
| 1839 | * establish the host. |
| 1840 | */ |
| 1841 | lpfc_get_cfgparam(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1842 | phba->max_vpi = LPFC_MAX_VPI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1843 | |
| 1844 | /* Initialize timers used by driver */ |
| 1845 | init_timer(&phba->fc_estabtmo); |
| 1846 | phba->fc_estabtmo.function = lpfc_establish_link_tmo; |
| 1847 | phba->fc_estabtmo.data = (unsigned long)phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1848 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1849 | init_timer(&phba->hb_tmofunc); |
| 1850 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 1851 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 1852 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1853 | psli = &phba->sli; |
| 1854 | init_timer(&psli->mbox_tmo); |
| 1855 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | psli->mbox_tmo.data = (unsigned long) phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1857 | init_timer(&phba->fcp_poll_timer); |
| 1858 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1859 | phba->fcp_poll_timer.data = (unsigned long) phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1860 | init_timer(&phba->fabric_block_timer); |
| 1861 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 1862 | phba->fabric_block_timer.data = (unsigned long) phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | pci_set_master(pdev); |
Randy Dunlap | 694625c | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 1865 | pci_try_set_mwi(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | |
| 1867 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) |
| 1868 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) |
| 1869 | goto out_idr_remove; |
| 1870 | |
| 1871 | /* |
| 1872 | * Get the bus address of Bar0 and Bar2 and the number of bytes |
| 1873 | * required by each mapping. |
| 1874 | */ |
| 1875 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); |
| 1876 | bar0map_len = pci_resource_len(phba->pcidev, 0); |
| 1877 | |
| 1878 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); |
| 1879 | bar2map_len = pci_resource_len(phba->pcidev, 2); |
| 1880 | |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1881 | /* Map HBA SLIM to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1883 | if (!phba->slim_memmap_p) { |
| 1884 | error = -ENODEV; |
| 1885 | dev_printk(KERN_ERR, &pdev->dev, |
| 1886 | "ioremap failed for SLIM memory.\n"); |
| 1887 | goto out_idr_remove; |
| 1888 | } |
| 1889 | |
| 1890 | /* Map HBA Control Registers to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 1892 | if (!phba->ctrl_regs_memmap_p) { |
| 1893 | error = -ENODEV; |
| 1894 | dev_printk(KERN_ERR, &pdev->dev, |
| 1895 | "ioremap failed for HBA control registers.\n"); |
| 1896 | goto out_iounmap_slim; |
| 1897 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | |
| 1899 | /* Allocate memory for SLI-2 structures */ |
| 1900 | phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE, |
| 1901 | &phba->slim2p_mapping, GFP_KERNEL); |
| 1902 | if (!phba->slim2p) |
| 1903 | goto out_iounmap; |
| 1904 | |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1905 | memset(phba->slim2p, 0, SLI2_SLIM_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1907 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 1908 | lpfc_sli_hbq_size(), |
| 1909 | &phba->hbqslimp.phys, |
| 1910 | GFP_KERNEL); |
| 1911 | if (!phba->hbqslimp.virt) |
| 1912 | goto out_free_slim; |
| 1913 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1914 | hbq_count = lpfc_sli_hbq_count(); |
| 1915 | ptr = phba->hbqslimp.virt; |
| 1916 | for (i = 0; i < hbq_count; ++i) { |
| 1917 | phba->hbqs[i].hbq_virt = ptr; |
| 1918 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 1919 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 1920 | sizeof(struct lpfc_hbq_entry)); |
| 1921 | } |
| 1922 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 1923 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 1924 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1925 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 1926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
| 1928 | lpfc_sli_setup(phba); |
| 1929 | lpfc_sli_queue_setup(phba); |
| 1930 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1931 | retval = lpfc_mem_alloc(phba); |
| 1932 | if (retval) { |
| 1933 | error = retval; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1934 | goto out_free_hbqslimp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1935 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1936 | |
| 1937 | /* Initialize and populate the iocb list per host. */ |
| 1938 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
| 1939 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1940 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | if (iocbq_entry == NULL) { |
| 1942 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 1943 | "expected %d count. Unloading driver.\n", |
| 1944 | __FUNCTION__, i, LPFC_IOCB_LIST_CNT); |
| 1945 | error = -ENOMEM; |
| 1946 | goto out_free_iocbq; |
| 1947 | } |
| 1948 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1949 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 1950 | if (iotag == 0) { |
| 1951 | kfree (iocbq_entry); |
| 1952 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
| 1953 | "Unloading driver.\n", |
| 1954 | __FUNCTION__); |
| 1955 | error = -ENOMEM; |
| 1956 | goto out_free_iocbq; |
| 1957 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | |
| 1959 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1960 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 1961 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1962 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /* Initialize HBA structure */ |
| 1966 | phba->fc_edtov = FF_DEF_EDTOV; |
| 1967 | phba->fc_ratov = FF_DEF_RATOV; |
| 1968 | phba->fc_altov = FF_DEF_ALTOV; |
| 1969 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 1970 | |
| 1971 | INIT_LIST_HEAD(&phba->work_list); |
| 1972 | phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); |
| 1973 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 1974 | |
| 1975 | /* Startup the kernel thread for this host adapter. */ |
| 1976 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 1977 | "lpfc_worker_%d", phba->brd_no); |
| 1978 | if (IS_ERR(phba->worker_thread)) { |
| 1979 | error = PTR_ERR(phba->worker_thread); |
| 1980 | goto out_free_iocbq; |
| 1981 | } |
| 1982 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | /* 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] | 1984 | spin_lock_init(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| 1986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1987 | /* Initialize list of fabric iocbs */ |
| 1988 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 1989 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1990 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1991 | if (!vport) |
| 1992 | goto out_kthread_stop; |
| 1993 | |
| 1994 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1995 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1996 | lpfc_debugfs_initialize(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1997 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1998 | pci_set_drvdata(pdev, shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1999 | |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2000 | if (phba->cfg_use_msi) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2001 | retval = pci_enable_msi(phba->pcidev); |
| 2002 | if (!retval) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2003 | phba->using_msi = 1; |
| 2004 | else |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2005 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2006 | "0452 Enable MSI failed, continuing " |
| 2007 | "with IRQ\n"); |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2008 | } |
| 2009 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2010 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2011 | LPFC_DRIVER_NAME, phba); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2012 | if (retval) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2014 | "0451 Enable interrupt handler failed\n"); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2015 | error = retval; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2016 | goto out_disable_msi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2017 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2019 | phba->MBslimaddr = phba->slim_memmap_p; |
| 2020 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 2021 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 2022 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 2023 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
| 2024 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2025 | if (lpfc_alloc_sysfs_attr(vport)) { |
| 2026 | error = -ENOMEM; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2027 | goto out_free_irq; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2028 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2030 | if (lpfc_sli_hba_setup(phba)) { |
| 2031 | error = -ENODEV; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2032 | goto out_remove_device; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2033 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2034 | |
| 2035 | /* |
| 2036 | * hba setup may have changed the hba_queue_depth so we need to adjust |
| 2037 | * the value of can_queue. |
| 2038 | */ |
| 2039 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 2040 | |
| 2041 | lpfc_host_attrib_init(shost); |
| 2042 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2043 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 2044 | spin_lock_irq(shost->host_lock); |
| 2045 | lpfc_poll_start_timer(phba); |
| 2046 | spin_unlock_irq(shost->host_lock); |
| 2047 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2048 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2049 | scsi_scan_host(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | return 0; |
| 2052 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2053 | out_remove_device: |
| 2054 | lpfc_free_sysfs_attr(vport); |
| 2055 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2056 | vport->load_flag |= FC_UNLOADING; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2057 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2058 | out_free_irq: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | lpfc_stop_phba_timers(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2060 | phba->pport->work_port_events = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | free_irq(phba->pcidev->irq, phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2062 | out_disable_msi: |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2063 | if (phba->using_msi) |
| 2064 | pci_disable_msi(phba->pcidev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2065 | destroy_port(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | out_kthread_stop: |
| 2067 | kthread_stop(phba->worker_thread); |
| 2068 | out_free_iocbq: |
| 2069 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 2070 | &phba->lpfc_iocb_list, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | kfree(iocbq_entry); |
| 2072 | phba->total_iocbq_bufs--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | } |
| 2074 | lpfc_mem_free(phba); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2075 | out_free_hbqslimp: |
| 2076 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
| 2077 | phba->hbqslimp.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | out_free_slim: |
| 2079 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p, |
| 2080 | phba->slim2p_mapping); |
| 2081 | out_iounmap: |
| 2082 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2083 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | iounmap(phba->slim_memmap_p); |
| 2085 | out_idr_remove: |
| 2086 | idr_remove(&lpfc_hba_index, phba->brd_no); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2087 | out_free_phba: |
| 2088 | kfree(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | out_release_regions: |
| 2090 | pci_release_regions(pdev); |
| 2091 | out_disable_device: |
| 2092 | pci_disable_device(pdev); |
| 2093 | out: |
James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 2094 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2095 | if (shost) |
| 2096 | scsi_host_put(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | return error; |
| 2098 | } |
| 2099 | |
| 2100 | static void __devexit |
| 2101 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 2102 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2103 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2104 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2105 | struct lpfc_hba *phba = vport->phba; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2106 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2107 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2108 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2110 | kfree(vport->vname); |
| 2111 | lpfc_free_sysfs_attr(vport); |
| 2112 | |
| 2113 | fc_remove_host(shost); |
| 2114 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2115 | lpfc_cleanup(vport); |
| 2116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2117 | /* |
| 2118 | * Bring down the SLI Layer. This step disable all interrupts, |
| 2119 | * clears the rings, discards all mailbox commands, and resets |
| 2120 | * the HBA. |
| 2121 | */ |
| 2122 | lpfc_sli_hba_down(phba); |
| 2123 | lpfc_sli_brdrestart(phba); |
| 2124 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2125 | lpfc_stop_phba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2126 | spin_lock_irq(&phba->hbalock); |
| 2127 | list_del_init(&vport->listentry); |
| 2128 | spin_unlock_irq(&phba->hbalock); |
| 2129 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2130 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2131 | |
| 2132 | kthread_stop(phba->worker_thread); |
| 2133 | |
| 2134 | /* Release the irq reservation */ |
| 2135 | free_irq(phba->pcidev->irq, phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2136 | if (phba->using_msi) |
| 2137 | pci_disable_msi(phba->pcidev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | |
| 2139 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2140 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2141 | |
| 2142 | /* |
| 2143 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 2144 | * corresponding pools here. |
| 2145 | */ |
| 2146 | lpfc_scsi_free(phba); |
| 2147 | lpfc_mem_free(phba); |
| 2148 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2149 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
| 2150 | phba->hbqslimp.phys); |
| 2151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | /* Free resources associated with SLI2 interface */ |
| 2153 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 2154 | phba->slim2p, phba->slim2p_mapping); |
| 2155 | |
| 2156 | /* unmap adapter SLIM and Control Registers */ |
| 2157 | iounmap(phba->ctrl_regs_memmap_p); |
| 2158 | iounmap(phba->slim_memmap_p); |
| 2159 | |
| 2160 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 2161 | |
| 2162 | kfree(phba); |
| 2163 | |
| 2164 | pci_release_regions(pdev); |
| 2165 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2168 | /** |
| 2169 | * lpfc_io_error_detected - called when PCI error is detected |
| 2170 | * @pdev: Pointer to PCI device |
| 2171 | * @state: The current pci conneection state |
| 2172 | * |
| 2173 | * This function is called after a PCI bus error affecting |
| 2174 | * this device has been detected. |
| 2175 | */ |
| 2176 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, |
| 2177 | pci_channel_state_t state) |
| 2178 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2179 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2180 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2181 | struct lpfc_sli *psli = &phba->sli; |
| 2182 | struct lpfc_sli_ring *pring; |
| 2183 | |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2184 | if (state == pci_channel_io_perm_failure) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2185 | return PCI_ERS_RESULT_DISCONNECT; |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2186 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2187 | pci_disable_device(pdev); |
| 2188 | /* |
| 2189 | * There may be I/Os dropped by the firmware. |
| 2190 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 2191 | * retry it after re-establishing link. |
| 2192 | */ |
| 2193 | pring = &psli->ring[psli->fcp_ring]; |
| 2194 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2195 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2196 | /* Release the irq reservation */ |
| 2197 | free_irq(phba->pcidev->irq, phba); |
| 2198 | if (phba->using_msi) |
| 2199 | pci_disable_msi(phba->pcidev); |
| 2200 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2201 | /* Request a slot reset. */ |
| 2202 | return PCI_ERS_RESULT_NEED_RESET; |
| 2203 | } |
| 2204 | |
| 2205 | /** |
| 2206 | * lpfc_io_slot_reset - called after the pci bus has been reset. |
| 2207 | * @pdev: Pointer to PCI device |
| 2208 | * |
| 2209 | * Restart the card from scratch, as if from a cold-boot. |
| 2210 | */ |
| 2211 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) |
| 2212 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2213 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2214 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2215 | struct lpfc_sli *psli = &phba->sli; |
| 2216 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2217 | |
| 2218 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 2219 | if (pci_enable_device_bars(pdev, bars)) { |
| 2220 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 2221 | "PCI device after reset.\n"); |
| 2222 | return PCI_ERS_RESULT_DISCONNECT; |
| 2223 | } |
| 2224 | |
| 2225 | pci_set_master(pdev); |
| 2226 | |
| 2227 | /* Re-establishing Link */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2228 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2229 | phba->pport->fc_flag |= FC_ESTABLISH_LINK; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2230 | spin_unlock_irq(shost->host_lock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2231 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2232 | spin_lock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2233 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2234 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2235 | |
| 2236 | |
| 2237 | /* Take device offline; this will perform cleanup */ |
| 2238 | lpfc_offline(phba); |
| 2239 | lpfc_sli_brdrestart(phba); |
| 2240 | |
| 2241 | return PCI_ERS_RESULT_RECOVERED; |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * lpfc_io_resume - called when traffic can start flowing again. |
| 2246 | * @pdev: Pointer to PCI device |
| 2247 | * |
| 2248 | * This callback is called when the error recovery driver tells us that |
| 2249 | * its OK to resume normal operation. |
| 2250 | */ |
| 2251 | static void lpfc_io_resume(struct pci_dev *pdev) |
| 2252 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2253 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2254 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2255 | |
| 2256 | if (lpfc_online(phba) == 0) { |
| 2257 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); |
| 2258 | } |
| 2259 | } |
| 2260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | static struct pci_device_id lpfc_id_table[] = { |
| 2262 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 2263 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2264 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 2265 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 2267 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2268 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 2269 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2270 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 2271 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2272 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 2273 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2274 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 2275 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2276 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 2277 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2278 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 2279 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2280 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 2281 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2282 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 2283 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2284 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 2285 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2286 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 2287 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2288 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 2289 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2290 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 2291 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 2293 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2294 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 2295 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2296 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 2297 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2298 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 2299 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2300 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 2301 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 2303 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2304 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 2305 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2306 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 2307 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2308 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 2309 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2310 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 2311 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2312 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 2313 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2314 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 2315 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2316 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 2317 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2318 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 2319 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2320 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 2321 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2322 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 2323 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2324 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 2325 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 2326 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 2327 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | { 0 } |
| 2329 | }; |
| 2330 | |
| 2331 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 2332 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2333 | static struct pci_error_handlers lpfc_err_handler = { |
| 2334 | .error_detected = lpfc_io_error_detected, |
| 2335 | .slot_reset = lpfc_io_slot_reset, |
| 2336 | .resume = lpfc_io_resume, |
| 2337 | }; |
| 2338 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2339 | static struct pci_driver lpfc_driver = { |
| 2340 | .name = LPFC_DRIVER_NAME, |
| 2341 | .id_table = lpfc_id_table, |
| 2342 | .probe = lpfc_pci_probe_one, |
| 2343 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | }; |
| 2346 | |
| 2347 | static int __init |
| 2348 | lpfc_init(void) |
| 2349 | { |
| 2350 | int error = 0; |
| 2351 | |
| 2352 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 2353 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2355 | if (lpfc_enable_npiv) { |
| 2356 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 2357 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 2358 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | lpfc_transport_template = |
| 2360 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2361 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2363 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2364 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2365 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 2366 | if (lpfc_vport_transport_template == NULL) { |
| 2367 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2368 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2369 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2370 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2372 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | fc_release_transport(lpfc_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2374 | fc_release_transport(lpfc_vport_transport_template); |
| 2375 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2376 | |
| 2377 | return error; |
| 2378 | } |
| 2379 | |
| 2380 | static void __exit |
| 2381 | lpfc_exit(void) |
| 2382 | { |
| 2383 | pci_unregister_driver(&lpfc_driver); |
| 2384 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2385 | if (lpfc_enable_npiv) |
| 2386 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | module_init(lpfc_init); |
| 2390 | module_exit(lpfc_exit); |
| 2391 | MODULE_LICENSE("GPL"); |
| 2392 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 2393 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 2394 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |