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