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