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