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